| 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.trmk.vcloud_0_8; |
| 20 | |
| 21 | import static org.jclouds.Constants.PROPERTY_API_VERSION; |
| 22 | import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; |
| 23 | import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME; |
| 24 | import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS; |
| 25 | import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION; |
| 26 | import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; |
| 27 | import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED; |
| 28 | import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA; |
| 29 | import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; |
| 30 | import static org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; |
| 31 | |
| 32 | import java.util.Properties; |
| 33 | |
| 34 | import org.jclouds.PropertiesBuilder; |
| 35 | import org.jclouds.trmk.vcloud_0_8.domain.FenceMode; |
| 36 | |
| 37 | /** |
| 38 | * Builds properties used in Terremark VCloud Clients |
| 39 | * |
| 40 | * @author Adrian Cole |
| 41 | */ |
| 42 | public class TerremarkVCloudPropertiesBuilder extends PropertiesBuilder { |
| 43 | @Override |
| 44 | protected Properties defaultProperties() { |
| 45 | Properties properties = super.defaultProperties(); |
| 46 | properties.setProperty(PROPERTY_API_VERSION, "0.8"); |
| 47 | properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); |
| 48 | properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + ""); |
| 49 | properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); |
| 50 | properties.setProperty("jclouds.dns_name_length_min", "1"); |
| 51 | properties.setProperty("jclouds.dns_name_length_max", "15"); |
| 52 | // with ssh key injection comes another reboot. allowing more time |
| 53 | properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 420l * 1000l + ""); |
| 54 | return properties; |
| 55 | } |
| 56 | |
| 57 | public TerremarkVCloudPropertiesBuilder(Properties properties) { |
| 58 | super(properties); |
| 59 | } |
| 60 | |
| 61 | void setExtensions() { |
| 62 | if (properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NS) == null) { |
| 63 | properties.setProperty( |
| 64 | PROPERTY_TERREMARK_EXTENSION_NS, |
| 65 | String.format("urn:tmrk:%s-%s", properties.getProperty(PROPERTY_TERREMARK_EXTENSION_NAME), |
| 66 | properties.getProperty(PROPERTY_TERREMARK_EXTENSION_VERSION))); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | protected void setNs() { |
| 71 | if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null) |
| 72 | properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, |
| 73 | "http://www.vmware.com/vcloud/v" + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA)); |
| 74 | } |
| 75 | |
| 76 | protected void setFenceMode() { |
| 77 | if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) { |
| 78 | if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8")) |
| 79 | properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut"); |
| 80 | else |
| 81 | properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString()); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | public TerremarkVCloudPropertiesBuilder withApiVersion(String version) { |
| 86 | properties.setProperty(PROPERTY_API_VERSION, "0.8"); |
| 87 | return this; |
| 88 | } |
| 89 | |
| 90 | public TerremarkVCloudPropertiesBuilder withSchemaVersion(String version) { |
| 91 | properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8"); |
| 92 | return this; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Properties build() { |
| 97 | setNs(); |
| 98 | setFenceMode(); |
| 99 | setExtensions(); |
| 100 | return super.build(); |
| 101 | } |
| 102 | } |