diff --git a/project/pom.xml b/project/pom.xml index e271b943fd..7d5271beda 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -617,7 +617,22 @@ pageTracker._trackPageview(); - + + + clojure-1.2 + + + org.clojure + clojure + 1.2.0-master-SNAPSHOT + + + org.clojure + clojure-contrib + 1.2.0-SNAPSHOT + + + diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index 5817db0f7c..d6dd95f4ae 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -19,6 +19,8 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; @@ -31,6 +33,7 @@ import java.net.URI; import java.util.Properties; import org.jclouds.PropertiesBuilder; +import org.jclouds.vcloud.domain.FenceMode; /** * Builds properties used in VCloud Clients @@ -44,7 +47,10 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder { properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 8 * 60 + ""); properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8"); - properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); + properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, + "http://vcloud.safesecureweb.com/ns/vcloud.xsd"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString()); return properties; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java index 48617d3d79..581a88437e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java @@ -22,12 +22,15 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DISK; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; +import java.net.URI; import java.util.Map; import java.util.Properties; import java.util.SortedMap; @@ -67,7 +70,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder protected final Map virtualHardwareToInstanceId = ImmutableMap.of( ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9"); - private final String defaultNetwork; + private final URI defaultNetwork; + private final FenceMode defaultFenceMode; + private final boolean defaultDhcpEnabled; /** * To allow for optional injection, since guice doesn't allow unresolved constants in @@ -89,13 +94,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, + @Named(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED) String defaultDhcpEnabled, + @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String defaultFenceMode, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network, OptionalConstantsHolder defaultsHolder) { this.ns = ns; this.schema = schema; this.stringBinder = stringBinder; this.defaultVirtualHardwareQuantity = Maps.newHashMap(); - this.defaultNetwork = network; + this.defaultNetwork = URI.create(network); + this.defaultFenceMode = FenceMode.fromValue(defaultFenceMode); + this.defaultDhcpEnabled = Boolean.parseBoolean(defaultDhcpEnabled); if (defaultsHolder.cpuCount != null) this.defaultVirtualHardwareQuantity.put(ResourceType.PROCESSOR, defaultsHolder.cpuCount); if (defaultsHolder.memorySizeMegabytes != null) @@ -115,6 +124,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder String name = checkNotNull(postParams.remove("name"), "name"); String template = checkNotNull(postParams.remove("template"), "template"); String network = postParams.remove("network"); + String fenceMode = postParams.remove("fenceMode"); + String dhcpEnabled = postParams.remove("dhcpEnabled"); + String networkName = postParams.remove("networkName"); SortedMap virtualHardwareQuantity = extractVirtualQuantityFromPostParams(postParams); @@ -126,10 +138,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder network = networkFromOptions != null ? networkFromOptions : network; properties.putAll(options.getProperties()); } - network = network == null ? defaultNetwork : network; try { stringBinder.bindToRequest(request, generateXml(name, template, properties, - virtualHardwareQuantity, network)); + virtualHardwareQuantity, networkName == null ? name : networkName, + fenceMode == null ? defaultFenceMode : FenceMode.fromValue(fenceMode), + dhcpEnabled == null ? defaultDhcpEnabled : Boolean.parseBoolean(dhcpEnabled), + network == null ? defaultNetwork : URI.create(network))); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (FactoryConfigurationError e) { @@ -151,8 +165,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder } protected String generateXml(String name, String template, Map properties, - SortedMap virtualHardwareQuantity, String network) - throws ParserConfigurationException, FactoryConfigurationError, TransformerException { + SortedMap virtualHardwareQuantity, String networkName, + FenceMode fenceMode, boolean dhcp, URI network) throws ParserConfigurationException, + FactoryConfigurationError, TransformerException { XMLBuilder rootBuilder = buildRoot(name); rootBuilder.e("VAppTemplate").a("href", template); @@ -160,7 +175,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams"); addPropertiesifPresent(instantiationParamsBuilder, properties); addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity); - addNetworkConfig(instantiationParamsBuilder, name, network); + addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, dhcp, network); Properties outputProperties = new Properties(); outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); return rootBuilder.asString(outputProperties); @@ -180,13 +195,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder } protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, - String network) { + FenceMode fenceMode, boolean dhcp, URI network) { XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e( "NetworkConfig").a("name", name); XMLBuilder featuresBuilder = networkConfigBuilder.e("Features"); - featuresBuilder.e("FenceMode").t(FenceMode.ALLOW_IN_OUT.value()); - featuresBuilder.e("Dhcp").t("false"); - networkConfigBuilder.e("NetworkAssociation").a("href", network); + featuresBuilder.e("FenceMode").t(fenceMode.value()); + featuresBuilder.e("Dhcp").t(dhcp + ""); + networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString()); } protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder, diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java index 191427b921..b1136fab7d 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/BaseVCloudComputeClient.java @@ -18,8 +18,8 @@ */ package org.jclouds.vcloud.compute; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import java.net.InetAddress; import java.util.Map; @@ -69,16 +69,14 @@ public class BaseVCloudComputeClient implements VCloudComputeClient { this.vAppStatusToNodeState = vAppStatusToNodeState; } - public Map start(String vDCId, String name, String templateId, int minCores, - int minMegs, Long diskSize, Map properties, int... portsToOpen) { - logger - .debug( - ">> instantiating vApp vDC(%s) name(%s) template(%s) minCores(%d) minMegs(%d) diskSize(%d) properties(%s) ", - vDCId, name, templateId, minCores, minMegs, diskSize, properties); - InstantiateVAppTemplateOptions options = processorCount(minCores).memory(minMegs) - .productProperties(properties); - if (diskSize != null) - options.disk(diskSize); + @Override + public Map start(String vDCId, String name, String templateId, + InstantiateVAppTemplateOptions options, int... portsToOpen) { + checkNotNull(options, "options"); + + logger.debug(">> instantiating vApp vDC(%s) name(%s) template(%s) options(%s) ", vDCId, name, + templateId, options); + VApp vAppResponse = client.instantiateVAppTemplateInVDC(vDCId, name, templateId, options); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java index 95f1cc363b..ac1561b6f0 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeClient.java @@ -22,7 +22,7 @@ import java.net.InetAddress; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.inject.ImplementedBy; @@ -50,10 +50,8 @@ public interface VCloudComputeClient { * amount of virtual cpu cores * @param megs * amount of ram in megabytes - * @param diskSizeKilobytes - * size of disk in kilobytes, null is ok - * @param properties - * sets product properties on the vApp + * @param options + * options for instantiating the vApp; null is ok * @param portsToOpen * opens the following ports on the public ip address * @return map contains at least the following properties @@ -62,8 +60,8 @@ public interface VCloudComputeClient { * login password * */ - Map start(String vDCId, String name, String templateId, int cores, int megs, - @Nullable Long diskSizeKilobytes, Map properties, int... portsToOpen); + Map start(String vDCId, String name, String templateId, + InstantiateVAppTemplateOptions options, int... portsToOpen); /** * returns a set of addresses that are only visible to the private network. diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 5765973b54..2b94d3a753 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -21,9 +21,12 @@ package org.jclouds.vcloud.compute.config; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.domain.OsFamily.UBUNTU; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import java.net.InetAddress; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -84,6 +87,7 @@ import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; @@ -189,11 +193,15 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Override public NodeMetadata execute(String tag, String name, Template template) { + + InstantiateVAppTemplateOptions options = processorCount( + Double.valueOf(template.getSize().getCores()).intValue()).memory( + template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); + + options.networkName("templateId=" + template.getImage().getId()); + Map metaMap = computeClient.start(template.getLocation().getId(), name, - template.getImage().getId(), Double.valueOf(template.getSize().getCores()) - .intValue(), template.getSize().getRam(), - template.getSize().getDisk() * 1024 * 1024l, ImmutableMap. of(), - template.getOptions().getInboundPorts()); + template.getImage().getId(), options, template.getOptions().getInboundPorts()); VApp vApp = client.getVApp(metaMap.get("id")); return newCreateNodeResponse(tag, template, metaMap, vApp); } @@ -306,10 +314,13 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { extra.put("processor/count", Iterables.getOnlyElement( vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)).getVirtualQuantity() + ""); - for (ResourceAllocation disk : vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)) { extra.put(String.format("disk_drive/%s/kb", disk.getId()), disk.getVirtualQuantity() + ""); } + + for (Entry net : vApp.getNetworkToAddresses().entries()) { + extra.put(String.format("network/%s/ip", net.getKey()), net.getValue().getHostAddress()); + } return extra; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java index 47dbf7d57e..ee83bf1056 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java @@ -24,6 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; import java.util.Map; +import org.jclouds.vcloud.domain.FenceMode; + import com.google.common.collect.Maps; /** @@ -38,6 +40,9 @@ public class InstantiateVAppTemplateOptions { private String diskSizeKilobytes; private String network; private Map properties = Maps.newTreeMap(); + private String fenceMode; + private String dhcpEnabled; + private String networkName; public InstantiateVAppTemplateOptions productProperty(String key, String value) { properties.put(checkNotNull(key, "key"), checkNotNull(value, "value")); @@ -55,6 +60,21 @@ public class InstantiateVAppTemplateOptions { return this; } + public InstantiateVAppTemplateOptions networkName(String networkName) { + this.networkName = checkNotNull(networkName, "networkName"); + return this; + } + + public InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) { + this.fenceMode = checkNotNull(fenceMode, "fenceMode").toString(); + return this; + } + + public InstantiateVAppTemplateOptions dhcpEnabled(boolean dhcpEnabled) { + this.dhcpEnabled = dhcpEnabled + ""; + return this; + } + public InstantiateVAppTemplateOptions memory(long megabytes) { checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512"); this.memorySizeMegabytes = megabytes + ""; @@ -88,6 +108,18 @@ public class InstantiateVAppTemplateOptions { return network; } + public String getNetworkName() { + return networkName; + } + + public String getFenceMode() { + return fenceMode; + } + + public String getDhcpEnabled() { + return dhcpEnabled; + } + public Map getProperties() { return properties; } @@ -126,6 +158,30 @@ public class InstantiateVAppTemplateOptions { return options.inNetwork(networkLocation); } + /** + * @see InstantiateVAppTemplateOptions#fenceMode(FenceMode) + */ + public static InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.fenceMode(fenceMode); + } + + /** + * @see InstantiateVAppTemplateOptions#dhcpEnabled(boolean) + */ + public static InstantiateVAppTemplateOptions dhcpEnabled(boolean dhcpEnabled) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.dhcpEnabled(dhcpEnabled); + } + + /** + * @see InstantiateVAppTemplateOptions#networkName(String) + */ + public static InstantiateVAppTemplateOptions networkName(String networkName) { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + return options.networkName(networkName); + } + /** * @see InstantiateVAppTemplateOptions#productProperty(String,String) */ @@ -143,4 +199,12 @@ public class InstantiateVAppTemplateOptions { } } + @Override + public String toString() { + return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + + memorySizeMegabytes + ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" + + network + ", networkName=" + networkName + ", fenceMode=" + fenceMode + + ", dhcpEnabled=" + dhcpEnabled + ", properties=" + properties + "]"; + } + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java index ad2ecd8bc9..8b9c77e7fe 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java @@ -39,6 +39,9 @@ public interface VCloudConstants { /** * megabytes */ + public static final String PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED = "jclouds.vcloud.defaults.dhcpenabled"; + public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode"; + public static final String PROPERTY_VCLOUD_DEFAULT_MEMORY = "jclouds.vcloud.defaults.memorysizemegabytes"; public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network"; /** diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index 7acdb50866..6ac5acb614 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -19,6 +19,8 @@ package org.jclouds.vcloud; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; @@ -43,6 +45,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; +import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.TasksList; @@ -517,6 +520,8 @@ public class VCloudAsyncClientTest extends RestClientTest { @Override protected void configure() { Properties props = new Properties(); + props.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false"); + props.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString()); props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcloud.safesecureweb.com/network/1990"); props.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java index 2854810cbf..27b23cb66f 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayloadTest.java @@ -34,6 +34,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.domain.ResourceType; import org.testng.annotations.Test; @@ -65,7 +66,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { } }); - public void testDefault() throws IOException { String expected = Utils.toStringAndClose(getClass().getResourceAsStream( "/newvapp-hosting.xml")); @@ -89,7 +89,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { verify(request); } - public void testWithProcessorMemoryDisk() throws IOException { String expected = Utils.toStringAndClose(getClass().getResourceAsStream( @@ -120,4 +119,33 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { verify(request); } + + public void testWithNetworkNameDhcpFenceMode() throws IOException { + String expected = Utils.toStringAndClose(getClass().getResourceAsStream( + "/newvapp-hostingnetworknamedhcpfencemode.xml")); + Multimap headers = Multimaps.synchronizedMultimap(HashMultimap + . create()); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce(); + expect(request.getHeaders()).andReturn(headers).atLeastOnce(); + request.setPayload(expected); + replay(request); + + BindInstantiateVAppTemplateParamsToXmlPayload binder = injector + .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "CentOS 01"); + map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"); + map.put("network", "https://vcloud.safesecureweb.com/network/1990"); + map.put("networkName", "aloha"); + map.put("fenceMode", FenceMode.BRIDGED.toString()); + map.put("dhcpEnabled", "true"); + + binder.bindToRequest(request, map); + verify(request); + + } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java index 3349f9e61e..b35673c1cf 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.compute; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -37,6 +38,7 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -86,11 +88,12 @@ public class VCloudComputeClientLiveTest { String serverName = getCompatibleServerName(toTest); int processorCount = 1; int memory = 512; - long disk = 10 * 1025 * 1024; - Map properties = ImmutableMap.of("foo", "bar"); - id = computeClient.start(client.getDefaultVDC().getId(), serverName, templateId, - processorCount, memory, disk, properties).get("id"); + InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024) + .productProperties(ImmutableMap.of("foo", "bar")); + + id = computeClient.start(client.getDefaultVDC().getId(), serverName, templateId, options) + .get("id"); Expectation expectation = expectationMap.get(toTest); VApp vApp = client.getVApp(id); @@ -136,7 +139,7 @@ public class VCloudComputeClientLiveTest { if (id != null) computeClient.stop(id); } - + @BeforeGroups(groups = { "live" }) public void setupClient() { String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); @@ -150,8 +153,7 @@ public class VCloudComputeClientLiveTest { client = injector.getInstance(VCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { })); - expectationMap = ImmutableMap. builder().put( - OsFamily.CENTOS, + expectationMap = ImmutableMap. builder().put(OsFamily.CENTOS, new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); service = "vcloudtest"; templateId = "3"; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 979ea4729f..42936fb731 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -55,6 +55,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest { assert allData.getExtra().get("processor/count") != null; assert allData.getExtra().get("disk_drive/1/kb") != null; assert allData.getExtra().get("memory/mb") != null; + System.out.println(allData.getExtra()); } } } \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java index 1618c9c860..d22386bbc6 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java @@ -18,15 +18,19 @@ */ package org.jclouds.vcloud.options; -import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.dhcpEnabled; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.fenceMode; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.networkName; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.testng.Assert.assertEquals; import java.net.URI; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.vcloud.domain.FenceMode; import org.testng.annotations.Test; import com.google.inject.Guice; @@ -104,4 +108,43 @@ public class InstantiateVAppTemplateOptionsTest { disk(0); } + @Test + public void testNetworkName() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.networkName("network"); + assertEquals(options.getNetworkName(), "network"); + } + + @Test + public void testNetworkNameStatic() { + InstantiateVAppTemplateOptions options = networkName("network"); + assertEquals(options.getNetworkName(), "network"); + } + + @Test + public void testFenceMode() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.fenceMode(FenceMode.BLOCK_IN_OUT); + assertEquals(options.getFenceMode(), "blockInOut"); + } + + @Test + public void testFenceModeStatic() { + InstantiateVAppTemplateOptions options = fenceMode(FenceMode.BLOCK_IN_OUT); + assertEquals(options.getFenceMode(), "blockInOut"); + } + + @Test + public void testDhcpEnabled() { + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); + options.dhcpEnabled(true); + assertEquals(options.getDhcpEnabled(), "true"); + } + + @Test + public void testDhcpEnabledStatic() { + InstantiateVAppTemplateOptions options = dhcpEnabled(true); + assertEquals(options.getDhcpEnabled(), "true"); + } + } diff --git a/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml b/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml new file mode 100644 index 0000000000..9abdad4c40 --- /dev/null +++ b/vcloud/core/src/test/resources/newvapp-hostingnetworknamedhcpfencemode.xml @@ -0,0 +1 @@ +bridgedtrue \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java index 88f571d108..adfef6c648 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.java @@ -18,12 +18,14 @@ */ package org.jclouds.vcloud.terremark.binders; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA; +import java.net.URI; import java.util.Map; import java.util.SortedMap; @@ -36,6 +38,7 @@ import javax.xml.transform.TransformerException; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; +import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.domain.ResourceType; import com.jamesmurty.utils.XMLBuilder; @@ -53,22 +56,25 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, + @Named(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED) String defaultDhcpEnabled, + @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String defaultFenceMode, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network, OptionalConstantsHolder optionalDefaults) { - super(stringBinder, ns, schema, network, optionalDefaults); + super(stringBinder, ns, schema, defaultDhcpEnabled, defaultFenceMode, network, + optionalDefaults); } @Override protected String generateXml(String name, String template, Map properties, - SortedMap virtualHardwareQuantity, String network) - throws ParserConfigurationException, FactoryConfigurationError, TransformerException { + SortedMap virtualHardwareQuantity, String networkName, + FenceMode fenceMode, boolean dhcp, URI network) throws ParserConfigurationException, + FactoryConfigurationError, TransformerException { checkNotNull(virtualHardwareQuantity.get(ResourceType.PROCESSOR), "cpuCount must be present in instantiateVapp on terremark"); checkNotNull(virtualHardwareQuantity.get(ResourceType.MEMORY), "memorySizeMegabytes must be present in instantiateVapp on terremark"); - checkArgument(virtualHardwareQuantity.get(ResourceType.DISK_DRIVE) == null, - "diskSizeKilobytes no settable on instantiateVapp on terremark"); - return super.generateXml(name, template, properties, virtualHardwareQuantity, network); + return super.generateXml(name, template, properties, virtualHardwareQuantity, networkName, + fenceMode, dhcp, network); } @Override diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index aaf2414b9c..975073469c 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -34,6 +34,7 @@ import org.jclouds.vcloud.compute.BaseVCloudComputeClient; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; @@ -68,10 +69,12 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient { } @Override - public Map start(String vDCId, String name, String templateId, int minCores, - int minMegs, Long diskSize, Map properties, int... portsToOpen) { - Map response = super.start(vDCId, name, templateId, minCores, minMegs, null, - properties, portsToOpen);// trmk does not support resizing the primary disk + public Map start(String vDCId, String name, String templateId, + InstantiateVAppTemplateOptions options, int... portsToOpen) { + if (options.getDiskSizeKilobytes() != null) { + logger.warn("trmk does not support resizing the primary disk; unsetting disk size"); + } + Map response = super.start(vDCId, name, templateId, options, portsToOpen); if (portsToOpen.length > 0) createPublicAddressMappedToPorts(response.get("id"), portsToOpen); return response; diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 5b19569310..b9525b092d 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -19,6 +19,8 @@ package org.jclouds.vcloud.terremark; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED; +import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE; @@ -48,6 +50,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Jsr330; import org.jclouds.util.Utils; +import org.jclouds.vcloud.domain.FenceMode; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.VCloudApi; @@ -561,6 +564,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest