| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.vcloud; |
| 20 | |
| 21 | import static org.jclouds.Constants.PROPERTY_API_VERSION; |
| 22 | import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; |
| 23 | import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; |
| 24 | import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; |
| 25 | import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; |
| 26 | import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; |
| 27 | import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; |
| 28 | |
| 29 | import java.util.Properties; |
| 30 | |
| 31 | import org.jclouds.PropertiesBuilder; |
| 32 | import org.jclouds.vcloud.domain.network.FenceMode; |
| 33 | |
| 34 | /** |
| 35 | * Builds properties used in VCloud Clients |
| 36 | * |
| 37 | * @author Adrian Cole |
| 38 | */ |
| 39 | public class VCloudPropertiesBuilder extends PropertiesBuilder { |
| 40 | @Override |
| 41 | protected Properties defaultProperties() { |
| 42 | Properties properties = super.defaultProperties(); |
| 43 | properties.setProperty(PROPERTY_API_VERSION, "1.0"); |
| 44 | properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1"); |
| 45 | properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); |
| 46 | properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); |
| 47 | properties.setProperty("jclouds.dns_name_length_min", "1"); |
| 48 | properties.setProperty("jclouds.dns_name_length_max", "80"); |
| 49 | properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString()); |
| 50 | // TODO integrate this with the {@link ComputeTimeouts} instead of having a single timeout for |
| 51 | // everything. |
| 52 | properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 600l * 1000l + ""); |
| 53 | return properties; |
| 54 | } |
| 55 | |
| 56 | public VCloudPropertiesBuilder(Properties properties) { |
| 57 | super(properties); |
| 58 | } |
| 59 | |
| 60 | protected void setNs() { |
| 61 | if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null) |
| 62 | properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v" |
| 63 | + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA)); |
| 64 | } |
| 65 | |
| 66 | public VCloudPropertiesBuilder withApiVersion(String version) { |
| 67 | properties.setProperty(PROPERTY_API_VERSION, "1.0"); |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | public VCloudPropertiesBuilder withSchemaVersion(String version) { |
| 72 | properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0"); |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Properties build() { |
| 78 | setNs(); |
| 79 | return super.build(); |
| 80 | } |
| 81 | } |