diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java index 760368ca5a..d7353a6f36 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudMediaType.java @@ -101,6 +101,16 @@ public interface VCloudMediaType { public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.virtualHardwareSection+xml"); + /** + * "application/vnd.vmware.vcloud.networkSection+xml" + */ + public final static String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml"; + /** + * "application/vnd.vmware.vcloud.networkSection+xml" + */ + public final static MediaType NETWORKSECTION_XML_TYPE = new MediaType("application", + "vnd.vmware.vcloud.networkSection+xml"); + /** * "application/vnd.vmware.vcloud.task+xml" */ 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 eb26a8b51a..922ef2997c 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 @@ -29,6 +29,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_S import java.net.URI; import java.util.Map; import java.util.Properties; +import java.util.Set; import javax.annotation.Resource; import javax.inject.Named; @@ -42,10 +43,17 @@ import org.jclouds.logging.Logger; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; import com.google.inject.Inject; import com.jamesmurty.utils.XMLBuilder; @@ -64,11 +72,14 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder protected final BindToStringPayload stringBinder; protected final URI defaultNetwork; protected final FenceMode defaultFenceMode; + protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate; @Inject - public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, - @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, - @Network URI network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { + public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate, + BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, + @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network, + @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { + this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate; this.ns = ns; this.schema = schema; this.stringBinder = stringBinder; @@ -83,27 +94,32 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; checkState(gRequest.getArgs() != null, "args should be initialized at this point"); String name = checkNotNull(postParams.remove("name"), "name"); - String template = checkNotNull(postParams.remove("template"), "template"); + final URI template = URI.create(checkNotNull(postParams.remove("template"), "template")); - String network = defaultNetwork.toASCIIString(); - FenceMode fenceMode = defaultFenceMode; - logger.warn("hack alert; we need to actually get the network name from the vAppTemplate's ovf:Network ovf:name"); - String networkName = "vAppNet-vApp Internal"; boolean deploy = true; boolean powerOn = true; - InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); - if (options != null) { - network = ifNullDefaultTo(options.getNetwork(), network); - fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode); + Set networkConfig = null; + + NetworknetworkConfigDecorator networknetworkConfigDecorator = new NetworknetworkConfigDecorator(template, + defaultNetwork, defaultFenceMode, defaultNetworkNameInTemplate); + + InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); + + if (options != null) { + if (options.getNetworkConfig().size() > 0) + networkConfig = Sets.newLinkedHashSet(Iterables.transform(options.getNetworkConfig(), + networknetworkConfigDecorator)); - networkName = ifNullDefaultTo(options.getNetworkName(), networkName); deploy = ifNullDefaultTo(options.shouldDeploy(), deploy); powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn); } + + if (networkConfig == null) + networkConfig = ImmutableSet.of(networknetworkConfigDecorator.apply(null)); + try { - stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkName, fenceMode, URI - .create(network))); + stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkConfig)); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } catch (FactoryConfigurationError e) { @@ -114,15 +130,68 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder } - protected String generateXml(String name, boolean deploy, boolean powerOn, String template, String networkName, - FenceMode fenceMode, URI network) throws ParserConfigurationException, FactoryConfigurationError, - TransformerException { + protected static final class NetworknetworkConfigDecorator implements Function { + private final URI template; + private final URI defaultNetwork; + private final FenceMode defaultFenceMode; + private final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate; + + protected NetworknetworkConfigDecorator(URI template, URI defaultNetwork, FenceMode defaultFenceMode, + DefaultNetworkNameInTemplate defaultNetworkNameInTemplate) { + this.template = checkNotNull(template, "template"); + this.defaultNetwork = checkNotNull(defaultNetwork, "defaultNetwork"); + this.defaultFenceMode = checkNotNull(defaultFenceMode, "defaultFenceMode"); + this.defaultNetworkNameInTemplate = checkNotNull(defaultNetworkNameInTemplate, "defaultNetworkNameInTemplate"); + } + + @Override + public NetworkConfig apply(NetworkConfig from) { + if (from == null) + return new NetworkConfig(defaultNetworkNameInTemplate.apply(template), defaultNetwork, defaultFenceMode); + URI network = ifNullDefaultTo(from.getParentNetwork(), defaultNetwork); + FenceMode fenceMode = ifNullDefaultTo(from.getFenceMode(), defaultFenceMode); + String networkName = from.getNetworkName() != null ? from.getNetworkName() : defaultNetworkNameInTemplate + .apply(template); + return new NetworkConfig(networkName, network, fenceMode); + } + } + + @Singleton + public static class DefaultNetworkNameInTemplate implements Function { + @Resource + protected Logger logger = Logger.NULL; + + private final VCloudClient client; + + @Inject + DefaultNetworkNameInTemplate(VCloudClient client) { + this.client = client; + } + + @Override + public String apply(URI template) { + String networkName; + VAppTemplate vAppTemplate = client.getVAppTemplate(template); + checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template); + Set networks = vAppTemplate.getNetworkSection().getNetworks(); + checkArgument(networks.size() > 0, "no networks found in vAppTemplate %s", vAppTemplate); + if (networks.size() > 1) + logger.warn("multiple networks found for %s, choosing first from: %s", vAppTemplate.getName(), networks); + networkName = Iterables.get(networks, 0).getName(); + return networkName; + } + + } + + protected String generateXml(String name, boolean deploy, boolean powerOn, URI template, + Iterable networkConfig) throws ParserConfigurationException, + FactoryConfigurationError, TransformerException { XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + ""); XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams"); - addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network); + addNetworkConfig(instantiationParamsBuilder, networkConfig); - rootBuilder.e("Source").a("href", template); + rootBuilder.e("Source").a("href", template.toASCIIString()); rootBuilder.e("AllEULAsAccepted").t("true"); Properties outputProperties = new Properties(); @@ -130,14 +199,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder return rootBuilder.asString(outputProperties); } - protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, FenceMode fenceMode, URI network) { + protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, + Iterable networkConfig) { XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection"); networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks"); - XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", name).e( - "Configuration"); - configurationBuilder.e("ParentNetwork").a("href", network.toASCIIString()); - if (fenceMode != null) { - configurationBuilder.e("FenceMode").t(fenceMode.toString()); + for (NetworkConfig n : networkConfig) { + XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", n.getNetworkName()) + .e("Configuration"); + configurationBuilder.e("ParentNetwork").a("href", n.getParentNetwork().toASCIIString()); + if (n.getFenceMode() != null) { + configurationBuilder.e("FenceMode").t(n.getFenceMode().toString()); + } } } @@ -162,7 +234,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters"); } - protected T ifNullDefaultTo(T value, T defaultValue) { + public static T ifNullDefaultTo(T value, T defaultValue) { return value != null ? value : checkNotNull(defaultValue, "defaultValue"); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java index 2a4458c06d..e8a0f37cfb 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.java @@ -44,11 +44,13 @@ import org.jclouds.http.HttpRequest; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.inject.Inject; import com.jamesmurty.utils.XMLBuilder; @@ -99,11 +101,14 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen String fenceMode = defaultFenceMode; String networkName = name; if (options != null) { - network = ifNullDefaultTo(options.getNetwork(), network); - fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode); - if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged")) - fenceMode = "allowInOut"; - networkName = ifNullDefaultTo(options.getNetworkName(), networkName); + if (options.getNetworkConfig().size() > 0) { + NetworkConfig config = Iterables.get(options.getNetworkConfig(), 0); + network = ifNullDefaultTo(config.getParentNetwork(), network); + fenceMode = ifNullDefaultTo(config.getFenceMode(), defaultFenceMode); + if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged")) + fenceMode = "allowInOut"; + networkName = ifNullDefaultTo(config.getNetworkName(), networkName); + } addQuantity(options, virtualHardwareQuantity); } try { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java index e71d7436f8..08fcbbb5fe 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java @@ -23,12 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Iterables.find; import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; +import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.domain.Location; +import org.jclouds.logging.Logger; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VAppTemplate; @@ -36,14 +38,20 @@ import org.jclouds.vcloud.domain.ovf.OvfEnvelope; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; +import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; /** * @author Adrian Cole */ public class SizeForVAppTemplate implements Function { + + @Resource + protected Logger logger = Logger.NULL; + private final VCloudClient client; private final FindLocationForResource findLocationForResource; private ReferenceType parent; @@ -61,19 +69,36 @@ public class SizeForVAppTemplate implements Function { @Override public Size apply(VAppTemplate from) { + checkNotNull(from, "VAppTemplate"); + + if (!from.isOvfDescriptorUploaded()) { + logger.warn("cannot parse size as ovf descriptor for %s is not uploaded", from); + return null; + } OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref()); + if (ovf == null) { + logger.warn("cannot parse size as no ovf envelope found for %s", from); + return null; + } Location location = findLocationForResource.apply(checkNotNull(parent, "parent")); - int ram = (int) find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), - resourceType(ResourceType.MEMORY)).getVirtualQuantity(); - ResourceAllocation diskR = find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), - resourceType(ResourceType.DISK_DRIVE)); + if (ovf.getVirtualSystem().getHardware().size() == 0) { + logger.warn("cannot parse size for %s as no hardware sections exist in ovf %s", ovf); + return null; + } + if (ovf.getVirtualSystem().getHardware().size() > 1) { + logger.warn("multiple hardware choices found. using first", ovf); + } + VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getHardware(), 0); + + int ram = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.MEMORY)).getVirtualQuantity(); + ResourceAllocation diskR = find(hardware.getResourceAllocations(), resourceType(ResourceType.DISK_DRIVE)); int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR .getVirtualQuantity()) / 1024l); - double cores = (int) find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), - resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(); + double cores = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)) + .getVirtualQuantity(); return new SizeImpl(from.getHref().toASCIIString(), from.getName() + String.format(": vpu(%.1f), ram(%d), disk(%d)", cores, ram, disk), from.getHref().toASCIIString(), diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java index ee625513da..e08c0930a1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/util/VCloudComputeUtils.java @@ -50,7 +50,7 @@ public class VCloudComputeUtils { return toComputeOs(vm.getOperatingSystem()); } - public static CIMOperatingSystem toComputeOs(org.jclouds.vcloud.domain.ovf.OperatingSystem os) { + public static CIMOperatingSystem toComputeOs(org.jclouds.vcloud.domain.ovf.OperatingSystemSection os) { return new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(os.getId()), null, null, os.getDescription()); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java index 0c3cdc5f1b..01027b482a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppTemplate.java @@ -25,6 +25,7 @@ import java.util.Set; import javax.annotation.Nullable; import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; import com.google.inject.ImplementedBy; @@ -88,4 +89,11 @@ public interface VAppTemplate extends ReferenceType { * @since vcloud api 1.0 */ Set getChildren(); + + /** + * description of the predefined vApp internal networks in this template + * + * @since vcloud api 1.0 + */ + VCloudNetworkSection getNetworkSection(); } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java index ddaf651055..be48594589 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java @@ -25,6 +25,7 @@ import javax.annotation.Nullable; import org.jclouds.vcloud.domain.internal.VmImpl; import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem; +import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware; import com.google.inject.ImplementedBy; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java index 043738f28b..cbd38fe2ac 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java @@ -32,6 +32,7 @@ import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.Vm; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -53,10 +54,11 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate private final boolean ovfDescriptorUploaded; private final String vAppScopedLocalId; private final Set children = Sets.newLinkedHashSet(); + private final VCloudNetworkSection networkSection; public VAppTemplateImpl(String name, String type, URI id, Status status, ReferenceType vdc, @Nullable String description, Iterable tasks, boolean ovfDescriptorUploaded, - @Nullable String vAppScopedLocalId, Iterable children) { + @Nullable String vAppScopedLocalId, Iterable children, VCloudNetworkSection networkSection) { super(name, type, id); this.status = checkNotNull(status, "status"); this.vdc = vdc;// TODO: once <1.0 is killed check not null @@ -65,6 +67,7 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate this.vAppScopedLocalId = vAppScopedLocalId; this.ovfDescriptorUploaded = ovfDescriptorUploaded; Iterables.addAll(this.children, checkNotNull(children, "children")); + this.networkSection = checkNotNull(networkSection, "networkSection"); } /** @@ -123,11 +126,21 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate return children; } + /** + * {@inheritDoc} + */ + @Override + public VCloudNetworkSection getNetworkSection() { + return networkSection; + } + @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); + result = prime * result + ((children == null) ? 0 : children.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((networkSection == null) ? 0 : networkSection.hashCode()); result = prime * result + (ovfDescriptorUploaded ? 1231 : 1237); result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); @@ -145,13 +158,33 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate if (getClass() != obj.getClass()) return false; VAppTemplateImpl other = (VAppTemplateImpl) obj; + if (children == null) { + if (other.children != null) + return false; + } else if (!children.equals(other.children)) + return false; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; + if (networkSection == null) { + if (other.networkSection != null) + return false; + } else if (!networkSection.equals(other.networkSection)) + return false; if (ovfDescriptorUploaded != other.ovfDescriptorUploaded) return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (tasks == null) { + if (other.tasks != null) + return false; + } else if (!tasks.equals(other.tasks)) + return false; if (vAppScopedLocalId == null) { if (other.vAppScopedLocalId != null) return false; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java index 6c35028980..8c8864fc8c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java @@ -29,9 +29,9 @@ import javax.annotation.Nullable; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Task; -import org.jclouds.vcloud.domain.VCloudVirtualHardware; import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem; +import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/NetworkConfig.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/NetworkConfig.java new file mode 100644 index 0000000000..b7250897f6 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/network/NetworkConfig.java @@ -0,0 +1,133 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.domain.network; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.annotation.Nullable; + +import org.jclouds.vcloud.domain.ovf.NetworkSection; + +/** + * + * @author Adrian Cole + */ +public class NetworkConfig { + @Nullable + private final String networkName; + private final URI parentNetwork; + @Nullable + private final FenceMode fenceMode; + + /** + * + * Create a new NetworkConfig. + * + * @param networkName + * a valid {@networkConfig + * org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the vapp + * template}, or null to have us choose default + * @param parentNetwork + * a valid {@networkConfig org.jclouds.vcloud.domain.Org#getNetworks in + * the Org} + * @param fenceMode + * how to manage the relationship between the two networks + */ + public NetworkConfig(String networkName, URI parentNetwork, FenceMode fenceMode) { + this.networkName = networkName; + this.parentNetwork = checkNotNull(parentNetwork, "parentNetwork"); + this.fenceMode = fenceMode; + } + + public NetworkConfig(URI parentNetwork) { + this(null, parentNetwork, null); + } + + /** + * A name for the network. If the {@link org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection} includes a {@link NetworkSection.Network} network + * element, the name you specify for the vApp network must match the name specified in that + * element’s name attribute. + * + * @return + */ + public String getNetworkName() { + return networkName; + } + + /** + * + * @return A reference to the organization network to which this network connects. + */ + public URI getParentNetwork() { + return parentNetwork; + } + + /** + * A value of bridged indicates that this vApp network is connected directly to the organization + * network. + */ + public FenceMode getFenceMode() { + return fenceMode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); + result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode()); + result = prime * result + ((networkName == null) ? 0 : networkName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkConfig other = (NetworkConfig) obj; + if (fenceMode == null) { + if (other.fenceMode != null) + return false; + } else if (!fenceMode.equals(other.fenceMode)) + return false; + if (parentNetwork == null) { + if (other.parentNetwork != null) + return false; + } else if (!parentNetwork.equals(other.parentNetwork)) + return false; + if (networkName == null) { + if (other.networkName != null) + return false; + } else if (!networkName.equals(other.networkName)) + return false; + return true; + } + + @Override + public String toString() { + return "[networkName=" + networkName + ", parentNetwork=" + parentNetwork + ", fenceMode=" + fenceMode + "]"; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/NetworkSection.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/NetworkSection.java new file mode 100644 index 0000000000..a56f96a0b1 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/NetworkSection.java @@ -0,0 +1,93 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.domain.ovf; + +import java.util.Set; + +import org.jclouds.vcloud.domain.ovf.network.Network; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * The NetworkSection element shall list all logical networks used in the OVF package. + * + * @author Adrian Cole + */ +public class NetworkSection { + private final String info; + private final Set networks = Sets.newLinkedHashSet(); + + public NetworkSection(String info, Iterable networks) { + this.info = info; + Iterables.addAll(this.networks, networks); + } + + public String getInfo() { + return info; + } + + /** + * All networks referred to from Connection elements in all {@link VirtualHardwareSection} elements shall + * be defined in the NetworkSection. + * + * @return + */ + public Set getNetworks() { + return networks; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((info == null) ? 0 : info.hashCode()); + result = prime * result + ((networks == null) ? 0 : networks.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + NetworkSection other = (NetworkSection) obj; + if (info == null) { + if (other.info != null) + return false; + } else if (!info.equals(other.info)) + return false; + if (networks == null) { + if (other.networks != null) + return false; + } else if (!networks.equals(other.networks)) + return false; + return true; + } + + @Override + public String toString() { + return "[info=" + info + ", networks=" + networks + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystemSection.java similarity index 92% rename from vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystem.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystemSection.java index f4bb581e88..1b6b022c2f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystem.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/OperatingSystemSection.java @@ -21,7 +21,7 @@ package org.jclouds.vcloud.domain.ovf; import javax.annotation.Nullable; -public class OperatingSystem { +public class OperatingSystemSection { @Nullable protected final Integer id; @@ -31,7 +31,7 @@ public class OperatingSystem { @Nullable protected final String description; - public OperatingSystem(@Nullable Integer id, @Nullable String info, @Nullable String description) { + public OperatingSystemSection(@Nullable Integer id, @Nullable String info, @Nullable String description) { this.id = id; this.info = info; this.description = description; @@ -79,7 +79,7 @@ public class OperatingSystem { return false; if (getClass() != obj.getClass()) return false; - OperatingSystem other = (OperatingSystem) obj; + OperatingSystemSection other = (OperatingSystemSection) obj; if (description == null) { if (other.description != null) return false; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/System.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/System.java index 6e629d2000..28229ec5bc 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/System.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/System.java @@ -21,17 +21,23 @@ package org.jclouds.vcloud.domain.ovf; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Set; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + public class System { protected final int id; protected final String name; protected final String identifier; - protected final String type; + protected final Set virtualSystemTypes = Sets.newLinkedHashSet(); - public System(int id, String name, String identifier, String type) { + public System(int id, String name, String identifier, Iterable virtualSystemTypes) { this.id = id; this.name = checkNotNull(name, "name"); this.identifier = checkNotNull(identifier, "identifier"); - this.type = checkNotNull(type, "type"); + Iterables.addAll(this.virtualSystemTypes, checkNotNull(virtualSystemTypes, "virtualSystemTypes")); + } public String getName() { @@ -46,8 +52,17 @@ public class System { return identifier; } - public String getType() { - return type; + /** + * specifies a virtual system virtualSystemTypes identifier, which is an implementation defined string that + * uniquely identifies the virtualSystemTypes of the virtual system. + * + *

+ * For example, a virtual system virtualSystemTypes identifier could be vmx-4 for VMware’s fourth-generation + * virtual hardware or xen-3 for Xen’s third-generation virtual hardware. + * + */ + public Set getVirtualSystemTypes() { + return virtualSystemTypes; } @Override @@ -57,7 +72,7 @@ public class System { result = prime * result + id; result = prime * result + ((identifier == null) ? 0 : identifier.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((virtualSystemTypes == null) ? 0 : virtualSystemTypes.hashCode()); return result; } @@ -82,17 +97,18 @@ public class System { return false; } else if (!name.equals(other.name)) return false; - if (type == null) { - if (other.type != null) + if (virtualSystemTypes == null) { + if (other.virtualSystemTypes != null) return false; - } else if (!type.equals(other.type)) + } else if (!virtualSystemTypes.equals(other.virtualSystemTypes)) return false; return true; } @Override public String toString() { - return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name + ", type=" + type + "]"; + return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name + ", virtualSystemTypes=" + + virtualSystemTypes + "]"; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudNetworkSection.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudNetworkSection.java new file mode 100644 index 0000000000..01e7d35c2e --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudNetworkSection.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.domain.ovf; + +import java.net.URI; + +import org.jclouds.vcloud.domain.ovf.network.Network; + +/** + * VCloud extension + */ +public class VCloudNetworkSection extends NetworkSection { + protected final String type; + protected final URI href; + + public VCloudNetworkSection(String type, URI href, String info, Iterable networks) { + super(info, networks); + this.type = type; + this.href = href; + } + + public String getType() { + return type; + } + + public URI getHref() { + return href; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((href == null) ? 0 : href.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + VCloudNetworkSection other = (VCloudNetworkSection) obj; + if (href == null) { + if (other.href != null) + return false; + } else if (!href.equals(other.href)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } + + @Override + public String toString() { + return "[href=" + getHref() + ", type=" + getType() + ", info=" + getInfo() + ", networks=" + getNetworks() + "]"; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudOperatingSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudOperatingSystem.java index db833acc0b..511f9394dc 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudOperatingSystem.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudOperatingSystem.java @@ -30,7 +30,7 @@ import org.jclouds.vcloud.domain.ReferenceType; /** * A description of the operating system supported by a virtual machine. */ -public class VCloudOperatingSystem extends OperatingSystem { +public class VCloudOperatingSystem extends OperatingSystemSection { protected final String type; protected final URI href; @Nullable diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudVirtualHardware.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudVirtualHardware.java similarity index 92% rename from vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudVirtualHardware.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudVirtualHardware.java index 7682ea7e78..0e9c0547f8 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VCloudVirtualHardware.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VCloudVirtualHardware.java @@ -17,17 +17,15 @@ * ==================================================================== */ -package org.jclouds.vcloud.domain; +package org.jclouds.vcloud.domain.ovf; import java.net.URI; -import org.jclouds.vcloud.domain.ovf.ResourceAllocation; -import org.jclouds.vcloud.domain.ovf.System; /** * A description of the virtual hardware supported by a virtual machine. */ -public class VCloudVirtualHardware extends VirtualHardware { +public class VCloudVirtualHardware extends VirtualHardwareSection { protected final String type; protected final URI href; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualHardware.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualHardwareSection.java similarity index 75% rename from vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualHardware.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualHardwareSection.java index bd9339ea73..da90b5507e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualHardware.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualHardwareSection.java @@ -17,29 +17,35 @@ * ==================================================================== */ -package org.jclouds.vcloud.domain; +package org.jclouds.vcloud.domain.ovf; + +import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; -import org.jclouds.vcloud.domain.ovf.ResourceAllocation; -import org.jclouds.vcloud.domain.ovf.System; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; /** - * A description of the virtual hardware supported by a virtual machine. + * + * The virtual hardware required by a virtual machine is specified in VirtualHardwareSection. + *

+ * This specification supports abstract or incomplete hardware descriptions in which only the major + * devices are described. The hypervisor is allowed to create additional virtual hardware + * controllers and devices, as long as the required devices listed in the descriptor are realized. */ -public class VirtualHardware { +public class VirtualHardwareSection { protected final String info; protected final System virtualSystem; protected final Set resourceAllocations = Sets.newLinkedHashSet(); - public VirtualHardware(String info, System virtualSystem, Iterable resourceAllocations) { + public VirtualHardwareSection(String info, System virtualSystem, + Iterable resourceAllocations) { this.info = info; this.virtualSystem = virtualSystem; - Iterables.addAll(this.resourceAllocations, resourceAllocations); + Iterables.addAll(this.resourceAllocations, checkNotNull(resourceAllocations, "resourceAllocations")); } public String getInfo() { @@ -77,7 +83,7 @@ public class VirtualHardware { return false; if (getClass() != obj.getClass()) return false; - VirtualHardware other = (VirtualHardware) obj; + VirtualHardwareSection other = (VirtualHardwareSection) obj; if (info == null) { if (other.info != null) return false; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualSystem.java index 64343be6d0..0afc741bc6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualSystem.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/VirtualSystem.java @@ -21,7 +21,11 @@ package org.jclouds.vcloud.domain.ovf; import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.vcloud.domain.VirtualHardware; +import java.util.Set; + + +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; /** * @author Adrian Cole @@ -30,15 +34,16 @@ public class VirtualSystem { private final String id; private final String info; private final String name; - private final OperatingSystem operatingSystem; - private final VirtualHardware hardware; + private final OperatingSystemSection operatingSystem; + private final Set hardware = Sets.newLinkedHashSet(); - public VirtualSystem(String id, String info, String name, OperatingSystem operatingSystem, VirtualHardware hardware) { + public VirtualSystem(String id, String info, String name, OperatingSystemSection operatingSystem, + Iterable hardware) { this.id = id; this.info = info; this.name = name; this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); - this.hardware = checkNotNull(hardware, "hardware"); + Iterables.addAll(this.hardware, checkNotNull(hardware, "hardware")); } public String getId() { @@ -53,11 +58,15 @@ public class VirtualSystem { return name; } - public OperatingSystem getOperatingSystem() { + public OperatingSystemSection getOperatingSystem() { return operatingSystem; } - public VirtualHardware getHardware() { + /** + * Each VirtualSystem element may contain one or more VirtualHardwareSection elements, each of + * which describes the virtual hardware required by the virtual system. + * */ + public Set getHardware() { return hardware; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/network/Network.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/network/Network.java new file mode 100644 index 0000000000..809c00de77 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ovf/network/Network.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.domain.ovf.network; + +/** + * + * @author Adrian Cole + */ +public class Network { + private final String name; + private final String description; + + public Network(String name, String description) { + this.name = name; + this.description = description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Network other = (Network) obj; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "Network [name=" + name + ", description=" + description + "]"; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } +} \ No newline at end of file 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 7492861561..7979674ddb 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 @@ -22,9 +22,13 @@ package org.jclouds.vcloud.options; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.net.URI; +import java.util.Set; -import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; + + + +import com.google.common.collect.Sets; /** * @@ -32,13 +36,12 @@ import org.jclouds.vcloud.domain.network.FenceMode; * */ public class InstantiateVAppTemplateOptions { + private Set networkConfig = Sets.newLinkedHashSet(); private String cpuCount; private String memorySizeMegabytes; private String diskSizeKilobytes; - private String network; - private FenceMode fenceMode; - private String networkName; + private boolean block = true; private boolean deploy = true; private boolean powerOn = true; @@ -85,19 +88,6 @@ public class InstantiateVAppTemplateOptions { return this; } - /** - * The name of the vApp internal network that you want to connect to a VDC network - */ - public InstantiateVAppTemplateOptions networkName(String networkName) { - this.networkName = checkNotNull(networkName, "networkName"); - return this; - } - - public InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) { - this.fenceMode = checkNotNull(fenceMode, "fenceMode"); - return this; - } - public InstantiateVAppTemplateOptions memory(long megabytes) { checkArgument(megabytes >= 1, "megabytes must be positive"); this.memorySizeMegabytes = megabytes + ""; @@ -110,11 +100,28 @@ public class InstantiateVAppTemplateOptions { return this; } - public InstantiateVAppTemplateOptions network(URI networkLocation) { - this.network = checkNotNull(networkLocation, "networkLocation").toASCIIString(); + /** + * {@networkConfig VAppTemplate}s have internal networks that can be connected in order to access + * the internet or other external networks. + * + *

default behaviour if you don't use this option

By default, we connect the first + * internal {@networkConfig + * org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the vapp template}to a + * default chosen from the org or specified via {@networkConfig + * org.jclouds.vcloud.reference.VCloudConstants#PROPERTY_VCLOUD_DEFAULT_NETWORK} using the + * {@networkConfig org.jclouds.vcloud.domain.FenceMode#BRIDGED} or an override + * set by the property {@networkConfig + * org.jclouds.vcloud.reference.VCloudConstants#PROPERTY_VCLOUD_DEFAULT_FENCEMODE}. + */ + public InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { + this.networkConfig.add(checkNotNull(networkConfig, "networkConfig")); return this; } + public Set getNetworkConfig() { + return networkConfig; + } + public String getCpuCount() { return cpuCount; } @@ -127,18 +134,6 @@ public class InstantiateVAppTemplateOptions { return diskSizeKilobytes; } - public String getNetwork() { - return network; - } - - public String getNetworkName() { - return networkName; - } - - public FenceMode getFenceMode() { - return fenceMode; - } - public static class Builder { /** @@ -190,27 +185,11 @@ public class InstantiateVAppTemplateOptions { } /** - * @see InstantiateVAppTemplateOptions#network(URI) + * @see InstantiateVAppTemplateOptions#addNetworkConfig */ - public static InstantiateVAppTemplateOptions inNetwork(URI networkLocation) { + public static InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - return options.network(networkLocation); - } - - /** - * @see InstantiateVAppTemplateOptions#fenceMode(FenceMode) - */ - public static InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) { - InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - return options.fenceMode(fenceMode); - } - - /** - * @see InstantiateVAppTemplateOptions#networkName(String) - */ - public static InstantiateVAppTemplateOptions networkName(String networkName) { - InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - return options.networkName(networkName); + return options.addNetworkConfig(networkConfig); } } @@ -218,20 +197,20 @@ public class InstantiateVAppTemplateOptions { @Override public String toString() { return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes - + ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" + network + ", networkName=" + networkName - + ", fenceMode=" + fenceMode + "]"; + + ", diskSizeKilobytes=" + diskSizeKilobytes + ", networkConfig=" + networkConfig + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + (block ? 1231 : 1237); result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode()); + result = prime * result + (deploy ? 1231 : 1237); result = prime * result + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode()); - result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); + result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode()); result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode()); - result = prime * result + ((network == null) ? 0 : network.hashCode()); - result = prime * result + ((networkName == null) ? 0 : networkName.hashCode()); + result = prime * result + (powerOn ? 1231 : 1237); return result; } @@ -244,35 +223,31 @@ public class InstantiateVAppTemplateOptions { if (getClass() != obj.getClass()) return false; InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj; + if (block != other.block) + return false; if (cpuCount == null) { if (other.cpuCount != null) return false; } else if (!cpuCount.equals(other.cpuCount)) return false; + if (deploy != other.deploy) + return false; if (diskSizeKilobytes == null) { if (other.diskSizeKilobytes != null) return false; } else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes)) return false; - if (fenceMode == null) { - if (other.fenceMode != null) + if (networkConfig == null) { + if (other.networkConfig != null) return false; - } else if (!fenceMode.equals(other.fenceMode)) + } else if (!networkConfig.equals(other.networkConfig)) return false; if (memorySizeMegabytes == null) { if (other.memorySizeMegabytes != null) return false; } else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes)) return false; - if (network == null) { - if (other.network != null) - return false; - } else if (!network.equals(other.network)) - return false; - if (networkName == null) { - if (other.networkName != null) - return false; - } else if (!networkName.equals(other.networkName)) + if (powerOn != other.powerOn) return false; return true; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java index d2f1b28608..2e116a95a6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java @@ -35,6 +35,8 @@ import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; +import org.jclouds.vcloud.xml.ovf.VCloudNetworkSectionHandler; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -48,11 +50,14 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult children = Sets.newLinkedHashSet(); + private VCloudNetworkSection networkSection; public VAppTemplate getResult() { return new VAppTemplateImpl(template.getName(), template.getType(), template.getHref(), status, vdc, description, - tasks, ovfDescriptorUploaded, vAppScopedLocalId, children); + tasks, ovfDescriptorUploaded, vAppScopedLocalId, children, networkSection); } @Override @@ -81,11 +88,15 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult { - private final VirtualHardwareHandler hardwareHandler; + private final VirtualHardwareSectionHandler hardwareHandler; private ReferenceType hardware; @Inject - public VCloudVirtualHardwareHandler(VirtualHardwareHandler hardwareHandler) { + public VCloudVirtualHardwareHandler(VirtualHardwareSectionHandler hardwareHandler) { this.hardwareHandler = hardwareHandler; } public VCloudVirtualHardware getResult() { - VirtualHardware hardware = hardwareHandler.getResult(); + VirtualHardwareSection hardware = hardwareHandler.getResult(); return new VCloudVirtualHardware(this.hardware.getType(), this.hardware.getHref(), hardware.getInfo(), hardware .getSystem(), hardware.getResourceAllocations()); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareSectionHandler.java similarity index 88% rename from vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareHandler.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareSectionHandler.java index 003c1a8284..60da4da0eb 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualHardwareSectionHandler.java @@ -24,9 +24,9 @@ import java.util.Set; import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; -import org.jclouds.vcloud.domain.VirtualHardware; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.System; +import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import org.jclouds.vcloud.xml.ovf.SystemHandler; import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationHandler; import org.xml.sax.Attributes; @@ -36,14 +36,14 @@ import com.google.common.collect.Sets; /** * @author Adrian Cole */ -public class VirtualHardwareHandler extends ParseSax.HandlerWithResult { +public class VirtualHardwareSectionHandler extends ParseSax.HandlerWithResult { protected StringBuilder currentText = new StringBuilder(); private final SystemHandler systemHandler; private final VCloudResourceAllocationHandler allocationHandler; @Inject - public VirtualHardwareHandler(SystemHandler systemHandler, VCloudResourceAllocationHandler allocationHandler) { + public VirtualHardwareSectionHandler(SystemHandler systemHandler, VCloudResourceAllocationHandler allocationHandler) { this.systemHandler = systemHandler; this.allocationHandler = allocationHandler; } @@ -55,8 +55,8 @@ public class VirtualHardwareHandler extends ParseSax.HandlerWithResult + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.xml.ovf; + +import java.util.Map; +import java.util.Set; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.ovf.NetworkSection; +import org.jclouds.vcloud.domain.ovf.network.Network; +import org.jclouds.vcloud.util.Utils; +import org.xml.sax.Attributes; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class NetworkSectionHandler extends ParseSax.HandlerWithResult { + protected StringBuilder currentText = new StringBuilder(); + + protected String info; + protected String name; + protected String description; + + protected Set networks = Sets.newLinkedHashSet(); + + public NetworkSection getResult() { + NetworkSection system = new NetworkSection(info, networks); + this.info = null; + this.networks = Sets.newLinkedHashSet(); + return system; + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.endsWith("Network")) { + name = attributes.get("name"); + } + } + + @Override + public void endElement(String uri, String localName, String qName) { + if (qName.endsWith("Info")) { + this.info = currentOrNull(); + } else if (qName.endsWith("Description")) { + this.description = currentOrNull(); + } else if (qName.endsWith("Network")) { + this.networks.add(new Network(name, description)); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemSectionHandler.java similarity index 87% rename from vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemHandler.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemSectionHandler.java index f1a93fce2d..13cdee5fe1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/OperatingSystemSectionHandler.java @@ -22,22 +22,22 @@ package org.jclouds.vcloud.xml.ovf; import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.vcloud.domain.ovf.OperatingSystem; +import org.jclouds.vcloud.domain.ovf.OperatingSystemSection; import org.jclouds.vcloud.util.Utils; import org.xml.sax.Attributes; /** * @author Adrian Cole */ -public class OperatingSystemHandler extends ParseSax.HandlerWithResult { +public class OperatingSystemSectionHandler extends ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); protected Integer id; protected String info; protected String description; - public OperatingSystem getResult() { - OperatingSystem system = new OperatingSystem(id, info, description); + public OperatingSystemSection getResult() { + OperatingSystemSection system = new OperatingSystemSection(id, info, description); id = null; info = null; description = null; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/ResourceAllocationHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/ResourceAllocationHandler.java index 55547cc403..82676ce484 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/ResourceAllocationHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/ResourceAllocationHandler.java @@ -19,9 +19,12 @@ package org.jclouds.vcloud.xml.ovf; +import java.util.Map; + import org.jclouds.http.functions.ParseSax; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceType; +import org.jclouds.vcloud.util.Utils; import org.xml.sax.Attributes; /** @@ -72,9 +75,10 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult attributes = Utils.cleanseAttributes(attrs); if (qName.endsWith("Connection")) { - connected = new Boolean(attributes.getValue(attributes.getIndex("connected"))); + connected = new Boolean(attributes.get("connected")); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/SystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/SystemHandler.java index c5fac5c2ef..42e2ba09a2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/SystemHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/SystemHandler.java @@ -19,10 +19,14 @@ package org.jclouds.vcloud.xml.ovf; +import java.util.Set; + import org.jclouds.http.functions.ParseSax; import org.jclouds.vcloud.domain.ovf.System; import org.xml.sax.Attributes; +import com.google.common.collect.Sets; + /** * @author Adrian Cole */ @@ -32,15 +36,15 @@ public class SystemHandler extends ParseSax.HandlerWithResult { private String elementName; private int instanceID; private String virtualSystemIdentifier; - private String virtualSystemType; + private Set virtualSystemTypes = Sets.newLinkedHashSet(); public System getResult() { System system = new org.jclouds.vcloud.domain.ovf.System(instanceID, elementName, virtualSystemIdentifier, - virtualSystemType); + virtualSystemTypes); this.elementName = null; this.instanceID = -1; this.virtualSystemIdentifier = null; - this.virtualSystemType = null; + this.virtualSystemTypes = null; return system; } @@ -57,7 +61,7 @@ public class SystemHandler extends ParseSax.HandlerWithResult { } else if (qName.endsWith("VirtualSystemIdentifier")) { this.virtualSystemIdentifier = currentText.toString().trim(); } else if (qName.endsWith("VirtualSystemType")) { - this.virtualSystemType = currentText.toString().trim(); + this.virtualSystemTypes.add(currentText.toString().trim()); } currentText = new StringBuilder(); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VCloudNetworkSectionHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VCloudNetworkSectionHandler.java new file mode 100644 index 0000000000..1ec59929c1 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VCloudNetworkSectionHandler.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.vcloud.xml.ovf; + +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.ovf.NetworkSection; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; +import org.jclouds.vcloud.util.Utils; +import org.xml.sax.Attributes; + +/** + * @author Adrian Cole + */ +public class VCloudNetworkSectionHandler extends ParseSax.HandlerWithResult { + private final NetworkSectionHandler networkSectionHandler; + + @Inject + VCloudNetworkSectionHandler(NetworkSectionHandler networkSectionHandler) { + this.networkSectionHandler = networkSectionHandler; + } + + private ReferenceType net; + + public VCloudNetworkSection getResult() { + NetworkSection system = networkSectionHandler.getResult(); + return new VCloudNetworkSection(net.getType(), net.getHref(), system.getInfo(), system.getNetworks()); + } + + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = Utils.cleanseAttributes(attrs); + if (qName.endsWith("NetworkSection")) { + this.net = Utils.newReferenceType(attributes); + } + networkSectionHandler.startElement(uri, localName, qName, attrs); + } + + @Override + public void endElement(String uri, String localName, String qName) { + networkSectionHandler.endElement(uri, localName, qName); + } + + public void characters(char ch[], int start, int length) { + networkSectionHandler.characters(ch, start, length); + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandler.java index ec3b9f42a9..63e69c1e77 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandler.java @@ -22,26 +22,29 @@ package org.jclouds.vcloud.xml.ovf; import static org.jclouds.vcloud.util.Utils.cleanseAttributes; import java.util.Map; +import java.util.Set; import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; -import org.jclouds.vcloud.domain.VirtualHardware; -import org.jclouds.vcloud.domain.ovf.OperatingSystem; +import org.jclouds.vcloud.domain.ovf.OperatingSystemSection; +import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import org.jclouds.vcloud.domain.ovf.VirtualSystem; -import org.jclouds.vcloud.xml.VirtualHardwareHandler; +import org.jclouds.vcloud.xml.VirtualHardwareSectionHandler; import org.xml.sax.Attributes; +import com.google.common.collect.Sets; + /** * @author Adrian Cole */ public class VirtualSystemHandler extends ParseSax.HandlerWithResult { protected StringBuilder currentText = new StringBuilder(); - private final OperatingSystemHandler osHandler; - private final VirtualHardwareHandler hardwareHandler; + private final OperatingSystemSectionHandler osHandler; + private final VirtualHardwareSectionHandler hardwareHandler; @Inject - public VirtualSystemHandler(OperatingSystemHandler osHandler, VirtualHardwareHandler hardwareHandler) { + public VirtualSystemHandler(OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) { this.osHandler = osHandler; this.hardwareHandler = hardwareHandler; } @@ -49,8 +52,8 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult hardware = Sets.newLinkedHashSet(); private boolean inHardware; private boolean inOs; @@ -63,7 +66,7 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult { - public void testInstantiateVAppTemplateInVDCURI() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, - String.class, InstantiateVAppTemplateOptions[].class); - HttpRequest request = processor.createRequest(method, URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp"); - - assertRequestLineEquals(request, - "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); - assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml")), - "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, VAppHandler.class); - assertExceptionParserClassEquals(method, null); - - checkFilters(request); - } - public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, String.class, InstantiateVAppTemplateOptions[].class); HttpRequest request = processor.createRequest(method, URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI - .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", networkName("aloha") - .fenceMode(FenceMode.NAT_ROUTED).network( - URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"))); + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", + addNetworkConfig(new NetworkConfig("aloha", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED))); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); @@ -146,7 +127,9 @@ public class VCloudAsyncClientTest extends RestClientTest { String.class, InstantiateVAppTemplateOptions[].class); processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512) - .disk(1024).network(URI.create("https://vcenterprise.bluelock.com/network/1990"))); + .disk(1024).addNetworkConfig( + new NetworkConfig(null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), + null))); } public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java index 13ee5465d7..1236cb64e1 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudExpressAsyncClientTest.java @@ -49,16 +49,17 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudExpressRestClientModule; -import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogItemImpl; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.OrgImpl; +import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -119,9 +120,12 @@ public class VCloudExpressAsyncClientTest extends RestClientTest of("vdc", new ReferenceTypeImpl("vdc", VCloudExpressMediaType.VDC_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap - . of(), - new ReferenceTypeImpl("tasksList", VCloudExpressMediaType.TASKSLIST_XML, URI + . of(), new ReferenceTypeImpl("tasksList", + VCloudExpressMediaType.TASKSLIST_XML, URI .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), ImmutableList - . of())); + . of())); } } 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 5a4f184478..e0e9243b36 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 @@ -24,6 +24,7 @@ import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; import java.io.IOException; import java.net.URI; @@ -34,12 +35,17 @@ import javax.inject.Singleton; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.util.Utils; +import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudPropertiesBuilder; +import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -54,24 +60,72 @@ import com.google.inject.name.Names; */ @Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest") public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { - Injector injector = Guice.createInjector(new AbstractModule() { + Injector createInjector(URI vAppTemplate, VAppTemplate value) { + final VCloudClient client = createMock(VCloudClient.class); - @Override - protected void configure() { - Properties props = new Properties(); - Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); - } + expect(client.getVAppTemplate(vAppTemplate)).andReturn(value).anyTimes(); + replay(client); - @SuppressWarnings("unused") - @Network - @Provides - @Singleton - URI provideNetwork() { - return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); - } - }); + return Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + Properties props = new Properties(); + Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties")); + bind(VCloudClient.class).toInstance(client); + } + + @SuppressWarnings("unused") + @Network + @Provides + @Singleton + URI provideNetwork() { + return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); + } + }); + } public void testDefault() throws IOException { + URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + VAppTemplate template = createMock(VAppTemplate.class); + VCloudNetworkSection net = createMock(VCloudNetworkSection.class); + + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml")); + GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); + expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce(); + request.setPayload(expected); + + expect(template.getNetworkSection()).andReturn(net).atLeastOnce(); + expect(net.getNetworks()) + .andReturn( + ImmutableSet + . of(new org.jclouds.vcloud.domain.ovf.network.Network( + "vAppNet-vApp Internal", null))); + + replay(request); + replay(template); + replay(net); + + BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance( + BindInstantiateVAppTemplateParamsToXmlPayload.class); + + Map map = Maps.newHashMap(); + map.put("name", "my-vapp"); + map.put("template", templateUri.toASCIIString()); + binder.bindToRequest(request, map); + + verify(request); + verify(template); + verify(net); + + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testWhenTemplateDoesntExist() throws IOException { + URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + VAppTemplate template = null; + String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml")); GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); @@ -79,12 +133,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance( + BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); - map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + map.put("template", templateUri.toASCIIString()); binder.bindToRequest(request, map); verify(request); @@ -93,6 +147,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { // TODO!!! figure out how to get this to work @Test(enabled = false) public void testWithProcessorMemoryDisk() throws IOException { + URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + VAppTemplate template = null; + InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); options.processorCount(1).memory(512).disk(1024); @@ -103,8 +160,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance( + BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); @@ -116,10 +173,11 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { } public void testWithNetworkNameFenceMode() throws IOException { + URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"); + VAppTemplate template = null; - InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - options.networkName("aloha").fenceMode(FenceMode.NAT_ROUTED).network( - URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991")); + InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("aloha", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)); String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml")); @@ -129,8 +187,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { request.setPayload(expected); replay(request); - BindInstantiateVAppTemplateParamsToXmlPayload binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); + BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance( + BindInstantiateVAppTemplateParamsToXmlPayload.class); Map map = Maps.newHashMap(); map.put("name", "my-vapp"); 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 fbfb5f9a03..c26ff7009c 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 @@ -19,11 +19,9 @@ package org.jclouds.vcloud.options; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; 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; @@ -31,8 +29,10 @@ import java.net.URI; import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.testng.annotations.Test; +import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Injector; @@ -47,17 +47,21 @@ public class InstantiateVAppTemplateOptionsTest { Injector injector = Guice.createInjector(new SaxParserModule()); @Test - public void testInNetwork() { + public void testAddNetworkConfig() { InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); - options.network(URI.create("http://localhost")); - assertEquals(options.getNetwork(), "http://localhost"); + options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED)); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default"); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost")); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED); } @Test - public void testInNetworkStatic() { - InstantiateVAppTemplateOptions options = inNetwork(URI - .create("http://localhost")); - assertEquals(options.getNetwork(), "http://localhost"); + public void testAddNetworkConfigStatic() { + InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default", URI + .create("http://localhost"), FenceMode.BRIDGED)); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default"); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost")); + assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED); } @Test @@ -103,31 +107,4 @@ public class InstantiateVAppTemplateOptionsTest { public void testDiskStaticWrong() { 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.BRIDGED); - assertEquals(options.getFenceMode(), FenceMode.BRIDGED); - } - - @Test - public void testFenceModeStatic() { - InstantiateVAppTemplateOptions options = fenceMode(FenceMode.BRIDGED); - assertEquals(options.getFenceMode(), FenceMode.BRIDGED); - } - } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java index f287294caf..8a0aba1a16 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java @@ -32,9 +32,12 @@ import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; +import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection; +import org.jclouds.vcloud.domain.ovf.network.Network; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Injector; @@ -73,6 +76,16 @@ public class VAppTemplateHandlerTest { assertEquals(vm.getDescription(), null); assertEquals(vm.getTasks(), ImmutableList.of()); assertEquals(vm.getVAppScopedLocalId(), "02_ubuntu_template"); + + VCloudNetworkSection network = result.getNetworkSection(); + assertEquals( + network.getHref(), + URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921/networkSection/")); + assertEquals(network.getType(), VCloudMediaType.NETWORKSECTION_XML); + assertEquals(network.getInfo(), "The list of logical networks"); + assertEquals(network.getNetworks(), ImmutableSet.of(new Network("vAppNet-vApp Internal", null))); + } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VmHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VmHandlerTest.java index 8ea6e45ceb..af60b79763 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VmHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VmHandlerTest.java @@ -32,6 +32,7 @@ import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.xml.ovf.VCloudOperatingSystemHandlerTest; +import org.jclouds.vcloud.xml.ovf.VCloudVirtualHardwareHandlerTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/SystemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/SystemHandlerTest.java index 8e8e1b748c..569fb4538b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/SystemHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/SystemHandlerTest.java @@ -27,6 +27,8 @@ import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.vcloud.domain.ovf.System; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** * Tests behavior of {@code SystemHandler} * @@ -40,7 +42,7 @@ public class SystemHandlerTest extends BaseHandlerTest { System result = factory.create(injector.getInstance(SystemHandler.class)).parse(is); - System expects = new System(0, "Virtual Hardware Family", "SimpleVM", "vmx-04"); + System expects = new System(0, "Virtual Hardware Family", "SimpleVM", ImmutableSet.of("vmx-04")); assertEquals(result, expects); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudExpressVAppHandlerTest.java similarity index 98% rename from vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppHandlerTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudExpressVAppHandlerTest.java index a76f01eab1..c18c7d1757 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudExpressVAppHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudExpressVAppHandlerTest.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.vcloud.xml; +package org.jclouds.vcloud.xml.ovf; import static org.testng.Assert.assertEquals; @@ -38,6 +38,7 @@ import org.jclouds.vcloud.domain.internal.VCloudExpressVAppImpl; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.System; +import org.jclouds.vcloud.xml.VCloudExpressVAppHandler; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -90,7 +91,7 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest { ListMultimap networkToAddresses = ImmutableListMultimap. of("Public Network", "10.150.4.93"); - System system = new System(0, "Virtual Hardware Family", "centos53", "vmx-07"); + System system = new System(0, "Virtual Hardware Family", "centos53", ImmutableSet.of("vmx-07")); Set resourceAllocations = ImmutableSet. of(new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, @@ -125,7 +126,7 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest { ListMultimap networkToAddresses = ImmutableListMultimap. of("Public Network", "10.23.119.221"); - System system = new System(0, "Virtual Hardware Family", "m1", "vmx-07"); + System system = new System(0, "Virtual Hardware Family", "m1", ImmutableSet.of("vmx-07")); Set resourceAllocations = ImmutableSet. of(new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudVirtualHardwareHandlerTest.java similarity index 96% rename from vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandlerTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudVirtualHardwareHandlerTest.java index 27f0c1ee2b..70b40645ea 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VCloudVirtualHardwareHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VCloudVirtualHardwareHandlerTest.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.vcloud.xml; +package org.jclouds.vcloud.xml.ovf; import static org.testng.Assert.assertEquals; @@ -26,7 +26,6 @@ import java.net.URI; import java.net.UnknownHostException; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.domain.VCloudVirtualHardware; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.ovf.EditableResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; @@ -34,8 +33,11 @@ import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter; +import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware; +import org.jclouds.vcloud.xml.VCloudVirtualHardwareHandler; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; /** @@ -57,7 +59,7 @@ public class VCloudVirtualHardwareHandlerTest extends BaseHandlerTest { @Test(enabled = false) public static void checkHardware(VCloudVirtualHardware result) { - System system = new System(0, "Virtual Hardware Family", "RHEL5", "vmx-07"); + System system = new System(0, "Virtual Hardware Family", "RHEL5", ImmutableSet.of("vmx-07")); assertEquals(result.getHref(), URI .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/")); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandlerTest.java index d08e97faaf..23df396d8b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ovf/VirtualSystemHandlerTest.java @@ -26,17 +26,17 @@ import java.io.InputStream; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.SaxParserModule; -import org.jclouds.vcloud.domain.VirtualHardware; -import org.jclouds.vcloud.domain.ovf.OperatingSystem; +import org.jclouds.vcloud.domain.ovf.OperatingSystemSection; import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter; +import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import org.jclouds.vcloud.domain.ovf.VirtualSystem; -import org.jclouds.vcloud.xml.ovf.VirtualSystemHandler; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Injector; @@ -61,13 +61,14 @@ public class VirtualSystemHandlerTest { assertEquals(result.getId(), "Ubuntu1004"); assertEquals(result.getName(), "Ubuntu1004"); assertEquals(result.getInfo(), "A virtual machine:"); - checkHardware(result.getHardware()); + checkHardware(Iterables.get(result.getHardware(), 0)); checkOs(result.getOperatingSystem()); } @Test(enabled = false) - public static void checkHardware(VirtualHardware result) { - assertEquals(result.getSystem(), new System(0, "Virtual Hardware Family", "Ubuntu1004", "vmx-07")); + public static void checkHardware(VirtualHardwareSection result) { + assertEquals(result.getSystem(), + new System(0, "Virtual Hardware Family", "Ubuntu1004", ImmutableSet.of("vmx-07"))); assertEquals(result.getInfo(), "Virtual hardware requirements"); assertEquals(Iterables.get(result.getResourceAllocations(), 0), new VCloudNetworkAdapter(1, "Network adapter 0", @@ -97,7 +98,7 @@ public class VirtualSystemHandlerTest { } @Test(enabled = false) - public static void checkOs(OperatingSystem result) { + public static void checkOs(OperatingSystemSection result) { assertEquals(result.getDescription(), "Ubuntu Linux (64-bit)"); assertEquals(result.getId(), new Integer(94)); assertEquals(result.getInfo(), "Specifies the operating system installed"); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java index 30e4c6c7bc..a518b8c4b0 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java @@ -19,9 +19,9 @@ package org.jclouds.vcloud.terremark.options; -import java.net.URI; import java.util.Map; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.inject.internal.util.Maps; @@ -92,11 +92,11 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp } /** - * @see TerremarkInstantiateVAppTemplateOptions#network(URI) + * @see TerremarkInstantiateVAppTemplateOptions#addNetworkConfig */ - public static TerremarkInstantiateVAppTemplateOptions inNetwork(URI networkLocation) { + public static TerremarkInstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); - return options.network(networkLocation); + return options.addNetworkConfig(networkConfig); } /** @@ -171,8 +171,8 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp } @Override - public TerremarkInstantiateVAppTemplateOptions network(URI networkLocation) { - return (TerremarkInstantiateVAppTemplateOptions) super.network(networkLocation); + public TerremarkInstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) { + return (TerremarkInstantiateVAppTemplateOptions) super.addNetworkConfig(networkConfig); } @Override diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java index 5f37472cb8..c73e905eb3 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkECloudAsyncClientTest.java @@ -50,6 +50,7 @@ import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExt import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.VCloudSession; +import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier; @@ -146,7 +147,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest of("10.114.34.132")); ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", @@ -147,7 +147,7 @@ public class VAppHandlerTest extends BaseHandlerTest { assertEquals(vApp.getVDC(), new ReferenceTypeImpl(null, VCloudExpressMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); - assertEquals(vApp.getSystem(), new System(0, "Virtual Hardware Family", "eduardo", "vmx-07")); + assertEquals(vApp.getSystem(), new System(0, "Virtual Hardware Family", "eduardo", ImmutableSet.of("vmx-07"))); assertEquals(vApp.getNetworkToAddresses().get("Internal"), ImmutableList.of("10.114.34.131")); ResourceAllocation cpu = new ResourceAllocation(1, "2 virtual CPU(s)", "Number of Virtual CPUs", diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/SystemHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ovf/SystemHandlerTest.java similarity index 91% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/SystemHandlerTest.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ovf/SystemHandlerTest.java index 647f825f5f..63a359dd32 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/SystemHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ovf/SystemHandlerTest.java @@ -17,7 +17,7 @@ * ==================================================================== */ -package org.jclouds.vcloud.terremark.xml; +package org.jclouds.vcloud.terremark.xml.ovf; import static org.testng.Assert.assertEquals; @@ -29,6 +29,8 @@ import org.jclouds.vcloud.xml.ovf.SystemHandler; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableSet; + /** * Tests behavior of {@code VirtualSystemHandler} * @@ -50,6 +52,6 @@ public class SystemHandlerTest extends BaseHandlerTest { assertEquals(result.getName(), "Virtual Hardware Family"); assertEquals(result.getId(), 0); assertEquals(result.getIdentifier(), "adriantest1"); - assertEquals(result.getType(), "vmx-07"); + assertEquals(result.getVirtualSystemTypes(), ImmutableSet.of("vmx-07")); } }