Issue 280 remodeled so that network connections can be propertly specified

This commit is contained in:
Adrian Cole 2010-08-26 14:18:43 -07:00
parent 025b8aa12d
commit 69bbd65c8d
47 changed files with 1090 additions and 311 deletions

View File

@ -101,6 +101,16 @@ public interface VCloudMediaType {
public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application", public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.virtualHardwareSection+xml"); "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" * "application/vnd.vmware.vcloud.task+xml"
*/ */

View File

@ -29,6 +29,7 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_S
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
@ -42,10 +43,17 @@ import org.jclouds.logging.Logger;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; 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.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; 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.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -64,11 +72,14 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final BindToStringPayload stringBinder; protected final BindToStringPayload stringBinder;
protected final URI defaultNetwork; protected final URI defaultNetwork;
protected final FenceMode defaultFenceMode; protected final FenceMode defaultFenceMode;
protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate;
@Inject @Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder, public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Network URI network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
this.ns = ns; this.ns = ns;
this.schema = schema; this.schema = schema;
this.stringBinder = stringBinder; this.stringBinder = stringBinder;
@ -83,27 +94,32 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name"); 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 deploy = true;
boolean powerOn = true; boolean powerOn = true;
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); Set<? extends NetworkConfig> networkConfig = null;
if (options != null) {
network = ifNullDefaultTo(options.getNetwork(), network); NetworknetworkConfigDecorator networknetworkConfigDecorator = new NetworknetworkConfigDecorator(template,
fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode); 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); deploy = ifNullDefaultTo(options.shouldDeploy(), deploy);
powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn); powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn);
} }
if (networkConfig == null)
networkConfig = ImmutableSet.of(networknetworkConfigDecorator.apply(null));
try { try {
stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkName, fenceMode, URI stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkConfig));
.create(network)));
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (FactoryConfigurationError 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, protected static final class NetworknetworkConfigDecorator implements Function<NetworkConfig, NetworkConfig> {
FenceMode fenceMode, URI network) throws ParserConfigurationException, FactoryConfigurationError, private final URI template;
TransformerException { 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<URI, String> {
@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<org.jclouds.vcloud.domain.ovf.network.Network> 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<? extends NetworkConfig> networkConfig) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + ""); XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams"); 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"); rootBuilder.e("AllEULAsAccepted").t("true");
Properties outputProperties = new Properties(); Properties outputProperties = new Properties();
@ -130,14 +199,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
return rootBuilder.asString(outputProperties); return rootBuilder.asString(outputProperties);
} }
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, FenceMode fenceMode, URI network) { protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
Iterable<? extends NetworkConfig> networkConfig) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection"); XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");
networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks"); networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks");
XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", name).e( for (NetworkConfig n : networkConfig) {
"Configuration"); XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", n.getNetworkName())
configurationBuilder.e("ParentNetwork").a("href", network.toASCIIString()); .e("Configuration");
if (fenceMode != null) { configurationBuilder.e("ParentNetwork").a("href", n.getParentNetwork().toASCIIString());
configurationBuilder.e("FenceMode").t(fenceMode.toString()); 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"); throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
} }
protected <T> T ifNullDefaultTo(T value, T defaultValue) { public static <T> T ifNullDefaultTo(T value, T defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue"); return value != null ? value : checkNotNull(defaultValue, "defaultValue");
} }
} }

View File

@ -44,11 +44,13 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder; import com.jamesmurty.utils.XMLBuilder;
@ -99,11 +101,14 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
String fenceMode = defaultFenceMode; String fenceMode = defaultFenceMode;
String networkName = name; String networkName = name;
if (options != null) { if (options != null) {
network = ifNullDefaultTo(options.getNetwork(), network); if (options.getNetworkConfig().size() > 0) {
fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode); NetworkConfig config = Iterables.get(options.getNetworkConfig(), 0);
if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged")) network = ifNullDefaultTo(config.getParentNetwork(), network);
fenceMode = "allowInOut"; fenceMode = ifNullDefaultTo(config.getFenceMode(), defaultFenceMode);
networkName = ifNullDefaultTo(options.getNetworkName(), networkName); if (apiVersion.indexOf("0.8") != -1 && fenceMode.equals("bridged"))
fenceMode = "allowInOut";
networkName = ifNullDefaultTo(config.getNetworkName(), networkName);
}
addQuantity(options, virtualHardwareQuantity); addQuantity(options, virtualHardwareQuantity);
} }
try { try {

View File

@ -23,12 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.find; import static com.google.common.collect.Iterables.find;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VAppTemplate; 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.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class SizeForVAppTemplate implements Function<VAppTemplate, Size> { public class SizeForVAppTemplate implements Function<VAppTemplate, Size> {
@Resource
protected Logger logger = Logger.NULL;
private final VCloudClient client; private final VCloudClient client;
private final FindLocationForResource findLocationForResource; private final FindLocationForResource findLocationForResource;
private ReferenceType parent; private ReferenceType parent;
@ -61,19 +69,36 @@ public class SizeForVAppTemplate implements Function<VAppTemplate, Size> {
@Override @Override
public Size apply(VAppTemplate from) { 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()); 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")); Location location = findLocationForResource.apply(checkNotNull(parent, "parent"));
int ram = (int) find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), if (ovf.getVirtualSystem().getHardware().size() == 0) {
resourceType(ResourceType.MEMORY)).getVirtualQuantity(); logger.warn("cannot parse size for %s as no hardware sections exist in ovf %s", ovf);
ResourceAllocation diskR = find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), return null;
resourceType(ResourceType.DISK_DRIVE)); }
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 int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR
.getVirtualQuantity()) / 1024l); .getVirtualQuantity()) / 1024l);
double cores = (int) find(ovf.getVirtualSystem().getHardware().getResourceAllocations(), double cores = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR))
resourceType(ResourceType.PROCESSOR)).getVirtualQuantity(); .getVirtualQuantity();
return new SizeImpl(from.getHref().toASCIIString(), from.getName() return new SizeImpl(from.getHref().toASCIIString(), from.getName()
+ String.format(": vpu(%.1f), ram(%d), disk(%d)", cores, ram, disk), from.getHref().toASCIIString(), + String.format(": vpu(%.1f), ram(%d), disk(%d)", cores, ram, disk), from.getHref().toASCIIString(),

View File

@ -50,7 +50,7 @@ public class VCloudComputeUtils {
return toComputeOs(vm.getOperatingSystem()); 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()); return new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(os.getId()), null, null, os.getDescription());
} }

View File

@ -25,6 +25,7 @@ import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
@ -88,4 +89,11 @@ public interface VAppTemplate extends ReferenceType {
* @since vcloud api 1.0 * @since vcloud api 1.0
*/ */
Set<? extends Vm> getChildren(); Set<? extends Vm> getChildren();
/**
* description of the predefined vApp internal networks in this template
*
* @since vcloud api 1.0
*/
VCloudNetworkSection getNetworkSection();
} }

View File

@ -25,6 +25,7 @@ import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.internal.VmImpl; import org.jclouds.vcloud.domain.internal.VmImpl;
import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem; import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem;
import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;

View File

@ -32,6 +32,7 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -53,10 +54,11 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate
private final boolean ovfDescriptorUploaded; private final boolean ovfDescriptorUploaded;
private final String vAppScopedLocalId; private final String vAppScopedLocalId;
private final Set<Vm> children = Sets.newLinkedHashSet(); private final Set<Vm> children = Sets.newLinkedHashSet();
private final VCloudNetworkSection networkSection;
public VAppTemplateImpl(String name, String type, URI id, Status status, ReferenceType vdc, public VAppTemplateImpl(String name, String type, URI id, Status status, ReferenceType vdc,
@Nullable String description, Iterable<Task> tasks, boolean ovfDescriptorUploaded, @Nullable String description, Iterable<Task> tasks, boolean ovfDescriptorUploaded,
@Nullable String vAppScopedLocalId, Iterable<? extends Vm> children) { @Nullable String vAppScopedLocalId, Iterable<? extends Vm> children, VCloudNetworkSection networkSection) {
super(name, type, id); super(name, type, id);
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
this.vdc = vdc;// TODO: once <1.0 is killed check not null 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.vAppScopedLocalId = vAppScopedLocalId;
this.ovfDescriptorUploaded = ovfDescriptorUploaded; this.ovfDescriptorUploaded = ovfDescriptorUploaded;
Iterables.addAll(this.children, checkNotNull(children, "children")); 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; return children;
} }
/**
* {@inheritDoc}
*/
@Override
public VCloudNetworkSection getNetworkSection() {
return networkSection;
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + ((children == null) ? 0 : children.hashCode());
result = prime * result + ((description == null) ? 0 : description.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 + (ovfDescriptorUploaded ? 1231 : 1237);
result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
@ -145,13 +158,33 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
VAppTemplateImpl other = (VAppTemplateImpl) obj; 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 (description == null) {
if (other.description != null) if (other.description != null)
return false; return false;
} else if (!description.equals(other.description)) } else if (!description.equals(other.description))
return false; return false;
if (networkSection == null) {
if (other.networkSection != null)
return false;
} else if (!networkSection.equals(other.networkSection))
return false;
if (ovfDescriptorUploaded != other.ovfDescriptorUploaded) if (ovfDescriptorUploaded != other.ovfDescriptorUploaded)
return false; 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 (vAppScopedLocalId == null) {
if (other.vAppScopedLocalId != null) if (other.vAppScopedLocalId != null)
return false; return false;

View File

@ -29,9 +29,9 @@ import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudVirtualHardware;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem; 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.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;

View File

@ -0,0 +1,133 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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
* elements 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 + "]";
}
}

View File

@ -0,0 +1,93 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Network> networks = Sets.newLinkedHashSet();
public NetworkSection(String info, Iterable<Network> 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<Network> 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 + "]";
}
}

View File

@ -21,7 +21,7 @@ package org.jclouds.vcloud.domain.ovf;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class OperatingSystem { public class OperatingSystemSection {
@Nullable @Nullable
protected final Integer id; protected final Integer id;
@ -31,7 +31,7 @@ public class OperatingSystem {
@Nullable @Nullable
protected final String description; 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.id = id;
this.info = info; this.info = info;
this.description = description; this.description = description;
@ -79,7 +79,7 @@ public class OperatingSystem {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
OperatingSystem other = (OperatingSystem) obj; OperatingSystemSection other = (OperatingSystemSection) obj;
if (description == null) { if (description == null) {
if (other.description != null) if (other.description != null)
return false; return false;

View File

@ -21,17 +21,23 @@ package org.jclouds.vcloud.domain.ovf;
import static com.google.common.base.Preconditions.checkNotNull; 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 { public class System {
protected final int id; protected final int id;
protected final String name; protected final String name;
protected final String identifier; protected final String identifier;
protected final String type; protected final Set<String> virtualSystemTypes = Sets.newLinkedHashSet();
public System(int id, String name, String identifier, String type) { public System(int id, String name, String identifier, Iterable<String> virtualSystemTypes) {
this.id = id; this.id = id;
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.identifier = checkNotNull(identifier, "identifier"); this.identifier = checkNotNull(identifier, "identifier");
this.type = checkNotNull(type, "type"); Iterables.addAll(this.virtualSystemTypes, checkNotNull(virtualSystemTypes, "virtualSystemTypes"));
} }
public String getName() { public String getName() {
@ -46,8 +52,17 @@ public class System {
return identifier; 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.
*
* <p/>
* For example, a virtual system virtualSystemTypes identifier could be vmx-4 for VMwares fourth-generation
* virtual hardware or xen-3 for Xens third-generation virtual hardware.
*
*/
public Set<String> getVirtualSystemTypes() {
return virtualSystemTypes;
} }
@Override @Override
@ -57,7 +72,7 @@ public class System {
result = prime * result + id; result = prime * result + id;
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode()); result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((name == null) ? 0 : name.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; return result;
} }
@ -82,17 +97,18 @@ public class System {
return false; return false;
} else if (!name.equals(other.name)) } else if (!name.equals(other.name))
return false; return false;
if (type == null) { if (virtualSystemTypes == null) {
if (other.type != null) if (other.virtualSystemTypes != null)
return false; return false;
} else if (!type.equals(other.type)) } else if (!virtualSystemTypes.equals(other.virtualSystemTypes))
return false; return false;
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name + ", type=" + type + "]"; return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name + ", virtualSystemTypes="
+ virtualSystemTypes + "]";
} }
} }

View File

@ -0,0 +1,82 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Network> 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() + "]";
}
}

View File

@ -30,7 +30,7 @@ import org.jclouds.vcloud.domain.ReferenceType;
/** /**
* A description of the operating system supported by a virtual machine. * 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 String type;
protected final URI href; protected final URI href;
@Nullable @Nullable

View File

@ -17,17 +17,15 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain.ovf;
import java.net.URI; 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. * 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 String type;
protected final URI href; protected final URI href;

View File

@ -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 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.Iterables;
import com.google.common.collect.Sets; 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.
* <p/>
* 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 String info;
protected final System virtualSystem; protected final System virtualSystem;
protected final Set<ResourceAllocation> resourceAllocations = Sets.newLinkedHashSet(); protected final Set<ResourceAllocation> resourceAllocations = Sets.newLinkedHashSet();
public VirtualHardware(String info, System virtualSystem, Iterable<? extends ResourceAllocation> resourceAllocations) { public VirtualHardwareSection(String info, System virtualSystem,
Iterable<? extends ResourceAllocation> resourceAllocations) {
this.info = info; this.info = info;
this.virtualSystem = virtualSystem; this.virtualSystem = virtualSystem;
Iterables.addAll(this.resourceAllocations, resourceAllocations); Iterables.addAll(this.resourceAllocations, checkNotNull(resourceAllocations, "resourceAllocations"));
} }
public String getInfo() { public String getInfo() {
@ -77,7 +83,7 @@ public class VirtualHardware {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
VirtualHardware other = (VirtualHardware) obj; VirtualHardwareSection other = (VirtualHardwareSection) obj;
if (info == null) { if (info == null) {
if (other.info != null) if (other.info != null)
return false; return false;

View File

@ -21,7 +21,11 @@ package org.jclouds.vcloud.domain.ovf;
import static com.google.common.base.Preconditions.checkNotNull; 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 * @author Adrian Cole
@ -30,15 +34,16 @@ public class VirtualSystem {
private final String id; private final String id;
private final String info; private final String info;
private final String name; private final String name;
private final OperatingSystem operatingSystem; private final OperatingSystemSection operatingSystem;
private final VirtualHardware hardware; private final Set<VirtualHardwareSection> 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<? extends VirtualHardwareSection> hardware) {
this.id = id; this.id = id;
this.info = info; this.info = info;
this.name = name; this.name = name;
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem");
this.hardware = checkNotNull(hardware, "hardware"); Iterables.addAll(this.hardware, checkNotNull(hardware, "hardware"));
} }
public String getId() { public String getId() {
@ -53,11 +58,15 @@ public class VirtualSystem {
return name; return name;
} }
public OperatingSystem getOperatingSystem() { public OperatingSystemSection getOperatingSystem() {
return operatingSystem; 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<? extends VirtualHardwareSection> getHardware() {
return hardware; return hardware;
} }

View File

@ -0,0 +1,78 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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;
}
}

View File

@ -22,9 +22,13 @@ package org.jclouds.vcloud.options;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; 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 { public class InstantiateVAppTemplateOptions {
private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
private String cpuCount; private String cpuCount;
private String memorySizeMegabytes; private String memorySizeMegabytes;
private String diskSizeKilobytes; private String diskSizeKilobytes;
private String network;
private FenceMode fenceMode;
private String networkName;
private boolean block = true; private boolean block = true;
private boolean deploy = true; private boolean deploy = true;
private boolean powerOn = true; private boolean powerOn = true;
@ -85,19 +88,6 @@ public class InstantiateVAppTemplateOptions {
return this; 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) { public InstantiateVAppTemplateOptions memory(long megabytes) {
checkArgument(megabytes >= 1, "megabytes must be positive"); checkArgument(megabytes >= 1, "megabytes must be positive");
this.memorySizeMegabytes = megabytes + ""; this.memorySizeMegabytes = megabytes + "";
@ -110,11 +100,28 @@ public class InstantiateVAppTemplateOptions {
return this; 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.
*
* <h4>default behaviour if you don't use this option</h4> 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; return this;
} }
public Set<NetworkConfig> getNetworkConfig() {
return networkConfig;
}
public String getCpuCount() { public String getCpuCount() {
return cpuCount; return cpuCount;
} }
@ -127,18 +134,6 @@ public class InstantiateVAppTemplateOptions {
return diskSizeKilobytes; return diskSizeKilobytes;
} }
public String getNetwork() {
return network;
}
public String getNetworkName() {
return networkName;
}
public FenceMode getFenceMode() {
return fenceMode;
}
public static class Builder { 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(); InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.network(networkLocation); return options.addNetworkConfig(networkConfig);
}
/**
* @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);
} }
} }
@ -218,20 +197,20 @@ public class InstantiateVAppTemplateOptions {
@Override @Override
public String toString() { public String toString() {
return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes
+ ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" + network + ", networkName=" + networkName + ", diskSizeKilobytes=" + diskSizeKilobytes + ", networkConfig=" + networkConfig + "]";
+ ", fenceMode=" + fenceMode + "]";
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + (block ? 1231 : 1237);
result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode()); 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 + ((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 + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode());
result = prime * result + ((network == null) ? 0 : network.hashCode()); result = prime * result + (powerOn ? 1231 : 1237);
result = prime * result + ((networkName == null) ? 0 : networkName.hashCode());
return result; return result;
} }
@ -244,35 +223,31 @@ public class InstantiateVAppTemplateOptions {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj; InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj;
if (block != other.block)
return false;
if (cpuCount == null) { if (cpuCount == null) {
if (other.cpuCount != null) if (other.cpuCount != null)
return false; return false;
} else if (!cpuCount.equals(other.cpuCount)) } else if (!cpuCount.equals(other.cpuCount))
return false; return false;
if (deploy != other.deploy)
return false;
if (diskSizeKilobytes == null) { if (diskSizeKilobytes == null) {
if (other.diskSizeKilobytes != null) if (other.diskSizeKilobytes != null)
return false; return false;
} else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes)) } else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes))
return false; return false;
if (fenceMode == null) { if (networkConfig == null) {
if (other.fenceMode != null) if (other.networkConfig != null)
return false; return false;
} else if (!fenceMode.equals(other.fenceMode)) } else if (!networkConfig.equals(other.networkConfig))
return false; return false;
if (memorySizeMegabytes == null) { if (memorySizeMegabytes == null) {
if (other.memorySizeMegabytes != null) if (other.memorySizeMegabytes != null)
return false; return false;
} else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes)) } else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes))
return false; return false;
if (network == null) { if (powerOn != other.powerOn)
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))
return false; return false;
return true; return true;
} }

View File

@ -35,6 +35,8 @@ import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl; 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.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -48,11 +50,14 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
protected final TaskHandler taskHandler; protected final TaskHandler taskHandler;
protected final VmHandler vmHandler; protected final VmHandler vmHandler;
protected final VCloudNetworkSectionHandler networkSectionHandler;
@Inject @Inject
public VAppTemplateHandler(TaskHandler taskHandler, VmHandler vmHandler) { public VAppTemplateHandler(TaskHandler taskHandler, VmHandler vmHandler,
VCloudNetworkSectionHandler networkSectionHandler) {
this.taskHandler = taskHandler; this.taskHandler = taskHandler;
this.vmHandler = vmHandler; this.vmHandler = vmHandler;
this.networkSectionHandler = networkSectionHandler;
} }
protected StringBuilder currentText = new StringBuilder(); protected StringBuilder currentText = new StringBuilder();
@ -67,11 +72,13 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
private boolean inChildren; private boolean inChildren;
private boolean inTasks; private boolean inTasks;
private boolean inNetworkSection;
protected Set<Vm> children = Sets.newLinkedHashSet(); protected Set<Vm> children = Sets.newLinkedHashSet();
private VCloudNetworkSection networkSection;
public VAppTemplate getResult() { public VAppTemplate getResult() {
return new VAppTemplateImpl(template.getName(), template.getType(), template.getHref(), status, vdc, description, return new VAppTemplateImpl(template.getName(), template.getType(), template.getHref(), status, vdc, description,
tasks, ovfDescriptorUploaded, vAppScopedLocalId, children); tasks, ovfDescriptorUploaded, vAppScopedLocalId, children, networkSection);
} }
@Override @Override
@ -81,11 +88,15 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
inChildren = true; inChildren = true;
} else if (qName.endsWith("Tasks")) { } else if (qName.endsWith("Tasks")) {
inTasks = true; inTasks = true;
} else if (qName.endsWith("NetworkSection")) {
inNetworkSection = true;
} }
if (inChildren) { if (inChildren) {
vmHandler.startElement(uri, localName, qName, attrs); vmHandler.startElement(uri, localName, qName, attrs);
} else if (inTasks) { } else if (inTasks) {
taskHandler.startElement(uri, localName, qName, attrs); taskHandler.startElement(uri, localName, qName, attrs);
} else if (inNetworkSection) {
networkSectionHandler.startElement(uri, localName, qName, attrs);
} else if (qName.equals("VAppTemplate")) { } else if (qName.equals("VAppTemplate")) {
template = newReferenceType(attributes); template = newReferenceType(attributes);
if (attributes.containsKey("status")) if (attributes.containsKey("status"))
@ -103,11 +114,16 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
} else if (qName.endsWith("Tasks")) { } else if (qName.endsWith("Tasks")) {
inTasks = false; inTasks = false;
this.tasks.add(taskHandler.getResult()); this.tasks.add(taskHandler.getResult());
} else if (qName.endsWith("NetworkSection")) {
inNetworkSection = false;
this.networkSection = networkSectionHandler.getResult();
} }
if (inChildren) { if (inChildren) {
vmHandler.endElement(uri, name, qName); vmHandler.endElement(uri, name, qName);
} else if (inTasks) { } else if (inTasks) {
taskHandler.endElement(uri, name, qName); taskHandler.endElement(uri, name, qName);
} else if (inNetworkSection) {
networkSectionHandler.endElement(uri, name, qName);
} else if (qName.equals("Description")) { } else if (qName.equals("Description")) {
description = currentOrNull(); description = currentOrNull();
} else if (qName.equals("VAppScopedLocalId")) { } else if (qName.equals("VAppScopedLocalId")) {
@ -121,9 +137,12 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
if (inTasks) if (inTasks)
taskHandler.characters(ch, start, length); taskHandler.characters(ch, start, length);
if (inChildren) else if (inChildren)
vmHandler.characters(ch, start, length); vmHandler.characters(ch, start, length);
currentText.append(ch, start, length); else if (inNetworkSection)
networkSectionHandler.characters(ch, start, length);
else
currentText.append(ch, start, length);
} }
protected String currentOrNull() { protected String currentOrNull() {

View File

@ -28,8 +28,8 @@ import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudVirtualHardware; import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware;
import org.jclouds.vcloud.domain.VirtualHardware; import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
/** /**
@ -37,17 +37,17 @@ import org.xml.sax.Attributes;
*/ */
public class VCloudVirtualHardwareHandler extends ParseSax.HandlerWithResult<VCloudVirtualHardware> { public class VCloudVirtualHardwareHandler extends ParseSax.HandlerWithResult<VCloudVirtualHardware> {
private final VirtualHardwareHandler hardwareHandler; private final VirtualHardwareSectionHandler hardwareHandler;
private ReferenceType hardware; private ReferenceType hardware;
@Inject @Inject
public VCloudVirtualHardwareHandler(VirtualHardwareHandler hardwareHandler) { public VCloudVirtualHardwareHandler(VirtualHardwareSectionHandler hardwareHandler) {
this.hardwareHandler = hardwareHandler; this.hardwareHandler = hardwareHandler;
} }
public VCloudVirtualHardware getResult() { public VCloudVirtualHardware getResult() {
VirtualHardware hardware = hardwareHandler.getResult(); VirtualHardwareSection hardware = hardwareHandler.getResult();
return new VCloudVirtualHardware(this.hardware.getType(), this.hardware.getHref(), hardware.getInfo(), hardware return new VCloudVirtualHardware(this.hardware.getType(), this.hardware.getHref(), hardware.getInfo(), hardware
.getSystem(), hardware.getResourceAllocations()); .getSystem(), hardware.getResourceAllocations());
} }

View File

@ -24,9 +24,9 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; 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.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.System; 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.SystemHandler;
import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationHandler; import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -36,14 +36,14 @@ import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualHardwareHandler extends ParseSax.HandlerWithResult<VirtualHardware> { public class VirtualHardwareSectionHandler extends ParseSax.HandlerWithResult<VirtualHardwareSection> {
protected StringBuilder currentText = new StringBuilder(); protected StringBuilder currentText = new StringBuilder();
private final SystemHandler systemHandler; private final SystemHandler systemHandler;
private final VCloudResourceAllocationHandler allocationHandler; private final VCloudResourceAllocationHandler allocationHandler;
@Inject @Inject
public VirtualHardwareHandler(SystemHandler systemHandler, VCloudResourceAllocationHandler allocationHandler) { public VirtualHardwareSectionHandler(SystemHandler systemHandler, VCloudResourceAllocationHandler allocationHandler) {
this.systemHandler = systemHandler; this.systemHandler = systemHandler;
this.allocationHandler = allocationHandler; this.allocationHandler = allocationHandler;
} }
@ -55,8 +55,8 @@ public class VirtualHardwareHandler extends ParseSax.HandlerWithResult<VirtualHa
private boolean inItem; private boolean inItem;
private boolean inSystem; private boolean inSystem;
public VirtualHardware getResult() { public VirtualHardwareSection getResult() {
return new VirtualHardware(info, system, allocations); return new VirtualHardwareSection(info, system, allocations);
} }
public void startElement(String uri, String localName, String qName, Attributes attrs) { public void startElement(String uri, String localName, String qName, Attributes attrs) {

View File

@ -31,10 +31,10 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudVirtualHardware;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.internal.VmImpl; import org.jclouds.vcloud.domain.internal.VmImpl;
import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem; import org.jclouds.vcloud.domain.ovf.VCloudOperatingSystem;
import org.jclouds.vcloud.domain.ovf.VCloudVirtualHardware;
import org.jclouds.vcloud.xml.ovf.VCloudOperatingSystemHandler; import org.jclouds.vcloud.xml.ovf.VCloudOperatingSystemHandler;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<NetworkSection> {
protected StringBuilder currentText = new StringBuilder();
protected String info;
protected String name;
protected String description;
protected Set<Network> 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<String, String> 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;
}
}

View File

@ -22,22 +22,22 @@ package org.jclouds.vcloud.xml.ovf;
import java.util.Map; import java.util.Map;
import org.jclouds.http.functions.ParseSax; 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.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class OperatingSystemHandler extends ParseSax.HandlerWithResult<OperatingSystem> { public class OperatingSystemSectionHandler extends ParseSax.HandlerWithResult<OperatingSystemSection> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
protected Integer id; protected Integer id;
protected String info; protected String info;
protected String description; protected String description;
public OperatingSystem getResult() { public OperatingSystemSection getResult() {
OperatingSystem system = new OperatingSystem(id, info, description); OperatingSystemSection system = new OperatingSystemSection(id, info, description);
id = null; id = null;
info = null; info = null;
description = null; description = null;

View File

@ -19,9 +19,12 @@
package org.jclouds.vcloud.xml.ovf; package org.jclouds.vcloud.xml.ovf;
import java.util.Map;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
/** /**
@ -72,9 +75,10 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
} }
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) { public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> attributes = Utils.cleanseAttributes(attrs);
if (qName.endsWith("Connection")) { if (qName.endsWith("Connection")) {
connected = new Boolean(attributes.getValue(attributes.getIndex("connected"))); connected = new Boolean(attributes.get("connected"));
} }
} }

View File

@ -19,10 +19,14 @@
package org.jclouds.vcloud.xml.ovf; package org.jclouds.vcloud.xml.ovf;
import java.util.Set;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.System;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -32,15 +36,15 @@ public class SystemHandler extends ParseSax.HandlerWithResult<System> {
private String elementName; private String elementName;
private int instanceID; private int instanceID;
private String virtualSystemIdentifier; private String virtualSystemIdentifier;
private String virtualSystemType; private Set<String> virtualSystemTypes = Sets.newLinkedHashSet();
public System getResult() { public System getResult() {
System system = new org.jclouds.vcloud.domain.ovf.System(instanceID, elementName, virtualSystemIdentifier, System system = new org.jclouds.vcloud.domain.ovf.System(instanceID, elementName, virtualSystemIdentifier,
virtualSystemType); virtualSystemTypes);
this.elementName = null; this.elementName = null;
this.instanceID = -1; this.instanceID = -1;
this.virtualSystemIdentifier = null; this.virtualSystemIdentifier = null;
this.virtualSystemType = null; this.virtualSystemTypes = null;
return system; return system;
} }
@ -57,7 +61,7 @@ public class SystemHandler extends ParseSax.HandlerWithResult<System> {
} else if (qName.endsWith("VirtualSystemIdentifier")) { } else if (qName.endsWith("VirtualSystemIdentifier")) {
this.virtualSystemIdentifier = currentText.toString().trim(); this.virtualSystemIdentifier = currentText.toString().trim();
} else if (qName.endsWith("VirtualSystemType")) { } else if (qName.endsWith("VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim(); this.virtualSystemTypes.add(currentText.toString().trim());
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<VCloudNetworkSection> {
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<String, String> 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);
}
}

View File

@ -22,26 +22,29 @@ package org.jclouds.vcloud.xml.ovf;
import static org.jclouds.vcloud.util.Utils.cleanseAttributes; import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.VirtualHardware; import org.jclouds.vcloud.domain.ovf.OperatingSystemSection;
import org.jclouds.vcloud.domain.ovf.OperatingSystem; import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection;
import org.jclouds.vcloud.domain.ovf.VirtualSystem; 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 org.xml.sax.Attributes;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSystem> { public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSystem> {
protected StringBuilder currentText = new StringBuilder(); protected StringBuilder currentText = new StringBuilder();
private final OperatingSystemHandler osHandler; private final OperatingSystemSectionHandler osHandler;
private final VirtualHardwareHandler hardwareHandler; private final VirtualHardwareSectionHandler hardwareHandler;
@Inject @Inject
public VirtualSystemHandler(OperatingSystemHandler osHandler, VirtualHardwareHandler hardwareHandler) { public VirtualSystemHandler(OperatingSystemSectionHandler osHandler, VirtualHardwareSectionHandler hardwareHandler) {
this.osHandler = osHandler; this.osHandler = osHandler;
this.hardwareHandler = hardwareHandler; this.hardwareHandler = hardwareHandler;
} }
@ -49,8 +52,8 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
protected String id; protected String id;
protected String info; protected String info;
protected String name; protected String name;
protected OperatingSystem operatingSystem; protected OperatingSystemSection operatingSystem;
protected VirtualHardware hardware; protected Set<VirtualHardwareSection> hardware = Sets.newLinkedHashSet();
private boolean inHardware; private boolean inHardware;
private boolean inOs; private boolean inOs;
@ -63,7 +66,7 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
info = null; info = null;
name = null; name = null;
operatingSystem = null; operatingSystem = null;
hardware = null; hardware = Sets.newLinkedHashSet();
return vs; return vs;
} }
@ -97,7 +100,7 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
public void endElement(String uri, String localName, String qName) { public void endElement(String uri, String localName, String qName) {
if (qName.endsWith("VirtualHardwareSection")) { if (qName.endsWith("VirtualHardwareSection")) {
inHardware = false; inHardware = false;
hardware = hardwareHandler.getResult(); hardware.add(hardwareHandler.getResult());
} else if (qName.endsWith("OperatingSystemSection")) { } else if (qName.endsWith("OperatingSystemSection")) {
inOs = false; inOs = false;
operatingSystem = osHandler.getResult(); operatingSystem = osHandler.getResult();

View File

@ -22,7 +22,7 @@ package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY; import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.networkName; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -60,6 +60,7 @@ import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -95,35 +96,15 @@ import domain.VCloudVersionsAsyncClient;
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> { public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
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, public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI 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/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", networkName("aloha") .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp",
.fenceMode(FenceMode.NAT_ROUTED).network( addNetworkConfig(new NetworkConfig("aloha", URI
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"))); .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -146,7 +127,9 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI 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) .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 { public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {

View File

@ -49,16 +49,17 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule; import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.CatalogItemImpl; 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.OrgImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -119,9 +120,12 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1) .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp",
.memory(512).disk(1024).fenceMode(FenceMode.BRIDGED).network( processorCount(1).memory(512).disk(1024)
URI.create("https://vcloud.safesecureweb.com/network/1990"))); .addNetworkConfig(
new NetworkConfig(null, URI
.create("https://vcloud.safesecureweb.com/network/1990"),
FenceMode.BRIDGED)));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -144,7 +148,9 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512) .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512)
.disk(1024).network(URI.create("https://vcloud.safesecureweb.com/network/1990"))); .disk(1024).addNetworkConfig(
new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"), null)));
} }
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
@ -750,10 +756,10 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))), ImmutableMap
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudExpressMediaType.VDC_XML, .<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudExpressMediaType.VDC_XML,
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"))), ImmutableMap
.<String, ReferenceType> of(), .<String, ReferenceType> of(), new ReferenceTypeImpl("tasksList",
new ReferenceTypeImpl("tasksList", VCloudExpressMediaType.TASKSLIST_XML, URI VCloudExpressMediaType.TASKSLIST_XML, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), ImmutableList .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/1")), ImmutableList
.<Task> of())); .<Task> of()));
} }
} }

View File

@ -24,6 +24,7 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify; import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -34,12 +35,17 @@ import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudPropertiesBuilder; import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.network.FenceMode; 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.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -54,24 +60,72 @@ import com.google.inject.name.Names;
*/ */
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest") @Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlPayloadTest")
public class BindInstantiateVAppTemplateParamsToXmlPayloadTest { public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector createInjector(URI vAppTemplate, VAppTemplate value) {
final VCloudClient client = createMock(VCloudClient.class);
@Override expect(client.getVAppTemplate(vAppTemplate)).andReturn(value).anyTimes();
protected void configure() { replay(client);
Properties props = new Properties();
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
}
@SuppressWarnings("unused") return Guice.createInjector(new AbstractModule() {
@Network
@Provides @Override
@Singleton protected void configure() {
URI provideNetwork() { Properties props = new Properties();
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990"); 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 { 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
.<org.jclouds.vcloud.domain.ovf.network.Network> 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<String, String> 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")); String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
@ -79,12 +133,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
request.setPayload(expected); request.setPayload(expected);
replay(request); replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp"); 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); binder.bindToRequest(request, map);
verify(request); verify(request);
@ -93,6 +147,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
// TODO!!! figure out how to get this to work // TODO!!! figure out how to get this to work
@Test(enabled = false) @Test(enabled = false)
public void testWithProcessorMemoryDisk() throws IOException { 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(); InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.processorCount(1).memory(512).disk(1024); options.processorCount(1).memory(512).disk(1024);
@ -103,8 +160,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
request.setPayload(expected); request.setPayload(expected);
replay(request); replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp"); map.put("name", "my-vapp");
@ -116,10 +173,11 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
} }
public void testWithNetworkNameFenceMode() throws IOException { 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(); InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("aloha", URI
options.networkName("aloha").fenceMode(FenceMode.NAT_ROUTED).network( .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED));
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"));
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml")); String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml"));
@ -129,8 +187,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
request.setPayload(expected); request.setPayload(expected);
replay(request); replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class); BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp"); map.put("name", "my-vapp");

View File

@ -19,11 +19,9 @@
package org.jclouds.vcloud.options; 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.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.memory;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.networkName;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -31,8 +29,10 @@ import java.net.URI;
import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -47,17 +47,21 @@ public class InstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new SaxParserModule()); Injector injector = Guice.createInjector(new SaxParserModule());
@Test @Test
public void testInNetwork() { public void testAddNetworkConfig() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.network(URI.create("http://localhost")); options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED));
assertEquals(options.getNetwork(), "http://localhost"); 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 @Test
public void testInNetworkStatic() { public void testAddNetworkConfigStatic() {
InstantiateVAppTemplateOptions options = inNetwork(URI InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default", URI
.create("http://localhost")); .create("http://localhost"), FenceMode.BRIDGED));
assertEquals(options.getNetwork(), "http://localhost"); 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 @Test
@ -103,31 +107,4 @@ public class InstantiateVAppTemplateOptionsTest {
public void testDiskStaticWrong() { public void testDiskStaticWrong() {
disk(0); 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);
}
} }

View File

@ -32,9 +32,12 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; 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 org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -73,6 +76,16 @@ public class VAppTemplateHandlerTest {
assertEquals(vm.getDescription(), null); assertEquals(vm.getDescription(), null);
assertEquals(vm.getTasks(), ImmutableList.of()); assertEquals(vm.getTasks(), ImmutableList.of());
assertEquals(vm.getVAppScopedLocalId(), "02_ubuntu_template"); 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)));
} }
} }

View File

@ -32,6 +32,7 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.xml.ovf.VCloudOperatingSystemHandlerTest; import org.jclouds.vcloud.xml.ovf.VCloudOperatingSystemHandlerTest;
import org.jclouds.vcloud.xml.ovf.VCloudVirtualHardwareHandlerTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;

View File

@ -27,6 +27,8 @@ import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.System;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/** /**
* Tests behavior of {@code SystemHandler} * 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 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); assertEquals(result, expects);
} }

View File

@ -17,7 +17,7 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.xml; package org.jclouds.vcloud.xml.ovf;
import static org.testng.Assert.assertEquals; 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.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.System;
import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -90,7 +91,7 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest {
ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network", ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
"10.150.4.93"); "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<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1, Set<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1,
"1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, "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<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network", ListMultimap<String, String> networkToAddresses = ImmutableListMultimap.<String, String> of("Public Network",
"10.23.119.221"); "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<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1, Set<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1,
"1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null,

View File

@ -17,7 +17,7 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.xml; package org.jclouds.vcloud.xml.ovf;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -26,7 +26,6 @@ import java.net.URI;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.VCloudVirtualHardware;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.ovf.EditableResourceAllocation; import org.jclouds.vcloud.domain.ovf.EditableResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation; 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.System;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter; 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 org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
@ -57,7 +59,7 @@ public class VCloudVirtualHardwareHandlerTest extends BaseHandlerTest {
@Test(enabled = false) @Test(enabled = false)
public static void checkHardware(VCloudVirtualHardware result) { 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 assertEquals(result.getHref(), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/"));

View File

@ -26,17 +26,17 @@ import java.io.InputStream;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.vcloud.domain.VirtualHardware; import org.jclouds.vcloud.domain.ovf.OperatingSystemSection;
import org.jclouds.vcloud.domain.ovf.OperatingSystem;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation; import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType; import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.System; import org.jclouds.vcloud.domain.ovf.System;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter; 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.domain.ovf.VirtualSystem;
import org.jclouds.vcloud.xml.ovf.VirtualSystemHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -61,13 +61,14 @@ public class VirtualSystemHandlerTest {
assertEquals(result.getId(), "Ubuntu1004"); assertEquals(result.getId(), "Ubuntu1004");
assertEquals(result.getName(), "Ubuntu1004"); assertEquals(result.getName(), "Ubuntu1004");
assertEquals(result.getInfo(), "A virtual machine:"); assertEquals(result.getInfo(), "A virtual machine:");
checkHardware(result.getHardware()); checkHardware(Iterables.get(result.getHardware(), 0));
checkOs(result.getOperatingSystem()); checkOs(result.getOperatingSystem());
} }
@Test(enabled = false) @Test(enabled = false)
public static void checkHardware(VirtualHardware result) { public static void checkHardware(VirtualHardwareSection result) {
assertEquals(result.getSystem(), new System(0, "Virtual Hardware Family", "Ubuntu1004", "vmx-07")); assertEquals(result.getSystem(),
new System(0, "Virtual Hardware Family", "Ubuntu1004", ImmutableSet.of("vmx-07")));
assertEquals(result.getInfo(), "Virtual hardware requirements"); assertEquals(result.getInfo(), "Virtual hardware requirements");
assertEquals(Iterables.get(result.getResourceAllocations(), 0), new VCloudNetworkAdapter(1, "Network adapter 0", assertEquals(Iterables.get(result.getResourceAllocations(), 0), new VCloudNetworkAdapter(1, "Network adapter 0",
@ -97,7 +98,7 @@ public class VirtualSystemHandlerTest {
} }
@Test(enabled = false) @Test(enabled = false)
public static void checkOs(OperatingSystem result) { public static void checkOs(OperatingSystemSection result) {
assertEquals(result.getDescription(), "Ubuntu Linux (64-bit)"); assertEquals(result.getDescription(), "Ubuntu Linux (64-bit)");
assertEquals(result.getId(), new Integer(94)); assertEquals(result.getId(), new Integer(94));
assertEquals(result.getInfo(), "Specifies the operating system installed"); assertEquals(result.getInfo(), "Specifies the operating system installed");

View File

@ -19,9 +19,9 @@
package org.jclouds.vcloud.terremark.options; package org.jclouds.vcloud.terremark.options;
import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.internal.util.Maps; 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(); TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.network(networkLocation); return options.addNetworkConfig(networkConfig);
} }
/** /**
@ -171,8 +171,8 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp
} }
@Override @Override
public TerremarkInstantiateVAppTemplateOptions network(URI networkLocation) { public TerremarkInstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
return (TerremarkInstantiateVAppTemplateOptions) super.network(networkLocation); return (TerremarkInstantiateVAppTemplateOptions) super.addNetworkConfig(networkConfig);
} }
@Override @Override

View File

@ -50,6 +50,7 @@ import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExt
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier; import org.jclouds.vcloud.terremark.TerremarkVCloudExpressAsyncClientTest.TerremarkVCloudRestClientModuleExtension.TestOrgNameToKeysListSupplier;
@ -146,7 +147,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"), .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group") "name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").network(URI.create("http://network"))); .withPassword("password").inRow("row").addNetworkConfig(
new NetworkConfig(URI.create("http://network"))));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");

View File

@ -54,12 +54,13 @@ import org.jclouds.vcloud.VCloudExpressAsyncClientTest.VCloudRestClientModuleExt
import org.jclouds.vcloud.domain.AllocationModel; import org.jclouds.vcloud.domain.AllocationModel;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDCStatus; import org.jclouds.vcloud.domain.VDCStatus;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule; import org.jclouds.vcloud.terremark.config.TerremarkVCloudExpressRestClientModule;
@ -195,7 +196,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"), .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group") "name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").network(URI.create("http://network"))); .withPassword("password").inRow("row").addNetworkConfig(
new NetworkConfig(URI.create("http://network"))));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");

View File

@ -33,6 +33,7 @@ import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder; import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
@ -83,8 +84,8 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn( expect(request.getArgs()).andReturn(
new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup( new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup(
"group").withPassword("password").inRow("row").network(URI.create("http://network")) }) "group").withPassword("password").inRow("row").addNetworkConfig(
.atLeastOnce(); new NetworkConfig(URI.create("http://network"))) }).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown").atLeastOnce(); expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown").atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce(); expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setPayload(expected); request.setPayload(expected);

View File

@ -19,21 +19,23 @@
package org.jclouds.vcloud.terremark.options; package org.jclouds.vcloud.terremark.options;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.disk;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inGroup; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inGroup;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inNetwork;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inRow; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inRow;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.memory; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.memory;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.disk; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.withPassword; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.withPassword;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import org.jclouds.http.functions.config.SaxParserModule; 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 org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -87,16 +89,21 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
} }
@Test @Test
public void testInNetwork() { public void testAddNetworkConfig() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions(); TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.network(URI.create("http://localhost")); options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED));
assertEquals(options.getNetwork(), "http://localhost"); 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 @Test
public void testInNetworkStatic() { public void testAddNetworkConfigStatic() {
TerremarkInstantiateVAppTemplateOptions options = inNetwork(URI.create("http://localhost")); TerremarkInstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default", URI
assertEquals(options.getNetwork(), "http://localhost"); .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 @Test

View File

@ -109,7 +109,7 @@ public class VAppHandlerTest extends BaseHandlerTest {
assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudExpressMediaType.VDC_XML, URI assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudExpressMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(result.getSystem(), new System(0, "Virtual Hardware Family", "centos-53", "vmx-07")); assertEquals(result.getSystem(), new System(0, "Virtual Hardware Family", "centos-53", ImmutableSet.of("vmx-07")));
assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.<String> of("10.114.34.132")); assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.<String> of("10.114.34.132"));
ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", 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 assertEquals(vApp.getVDC(), new ReferenceTypeImpl(null, VCloudExpressMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); .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")); assertEquals(vApp.getNetworkToAddresses().get("Internal"), ImmutableList.of("10.114.34.131"));
ResourceAllocation cpu = new ResourceAllocation(1, "2 virtual CPU(s)", "Number of Virtual CPUs", ResourceAllocation cpu = new ResourceAllocation(1, "2 virtual CPU(s)", "Number of Virtual CPUs",

View File

@ -17,7 +17,7 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.terremark.xml; package org.jclouds.vcloud.terremark.xml.ovf;
import static org.testng.Assert.assertEquals; 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.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
/** /**
* Tests behavior of {@code VirtualSystemHandler} * Tests behavior of {@code VirtualSystemHandler}
* *
@ -50,6 +52,6 @@ public class SystemHandlerTest extends BaseHandlerTest {
assertEquals(result.getName(), "Virtual Hardware Family"); assertEquals(result.getName(), "Virtual Hardware Family");
assertEquals(result.getId(), 0); assertEquals(result.getId(), 0);
assertEquals(result.getIdentifier(), "adriantest1"); assertEquals(result.getIdentifier(), "adriantest1");
assertEquals(result.getType(), "vmx-07"); assertEquals(result.getVirtualSystemTypes(), ImmutableSet.of("vmx-07"));
} }
} }