mirror of https://github.com/apache/jclouds.git
Issue 112: Added catalog and template queries. clarified api syntax
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2478 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
98371e6b37
commit
ee1e4ca59c
|
@ -23,9 +23,11 @@
|
|||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||
|
||||
|
@ -47,20 +49,24 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TasksList;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.CatalogItemHandler;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
import org.jclouds.vcloud.xml.VAppHandler;
|
||||
import org.jclouds.vcloud.xml.VAppTemplateHandler;
|
||||
import org.jclouds.vcloud.xml.VDCHandler;
|
||||
|
||||
/**
|
||||
|
@ -85,6 +91,20 @@ public interface VCloudAsyncClient {
|
|||
@XMLResponseParser(CatalogHandler.class)
|
||||
Future<? extends Catalog> getCatalog();
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vAppTemplate/{vAppTemplateId}")
|
||||
@Consumes(VAPPTEMPLATE_XML)
|
||||
@XMLResponseParser(VAppTemplateHandler.class)
|
||||
Future<? extends VAppTemplate> getVAppTemplate(@PathParam("vAppTemplateId") String vAppTemplateId);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalogItem/{catalogItemId}")
|
||||
@Consumes(CATALOGITEM_XML)
|
||||
@XMLResponseParser(CatalogItemHandler.class)
|
||||
Future<? extends CatalogItem> getCatalogItem(@PathParam("catalogItemId") String catalogItemId);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}")
|
||||
|
@ -204,7 +224,8 @@ public interface VCloudAsyncClient {
|
|||
@Consumes(VAPP_XML)
|
||||
@XMLResponseParser(VAppHandler.class)
|
||||
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
Future<? extends VApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
|
||||
Future<? extends VApp> instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId,
|
||||
@MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TasksList;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
|
@ -51,6 +53,10 @@ public interface VCloudClient {
|
|||
|
||||
Catalog getCatalog();
|
||||
|
||||
CatalogItem getCatalogItem(String catalogItemId);
|
||||
|
||||
VAppTemplate getVAppTemplate(String vAppTemplateId);
|
||||
|
||||
VDC getVDC(String vDCId);
|
||||
|
||||
VDC getDefaultVDC();
|
||||
|
@ -96,6 +102,6 @@ public interface VCloudClient {
|
|||
|
||||
VApp getVApp(String appId);
|
||||
|
||||
VApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
VApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -121,4 +121,14 @@ public class VCloudMediaType {
|
|||
public final static MediaType VAPP_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.vApp+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
|
||||
*/
|
||||
public final static String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.vAppTemplate+xml"
|
||||
*/
|
||||
public final static MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application",
|
||||
"vnd.vmware.vcloud.vAppTemplate+xml");
|
||||
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
package org.jclouds.vcloud;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
@ -48,8 +48,8 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder {
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
|
||||
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + "");
|
||||
properties.setProperty(PROPERTY_VCLOUD_DEFAULTCPUCOUNT, "1");
|
||||
properties.setProperty(PROPERTY_VCLOUD_DEFAULTMEMORY, "512");
|
||||
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/0.8");
|
||||
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,25 +26,35 @@ package org.jclouds.vcloud.binders;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DISK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -54,23 +64,50 @@ import com.google.common.collect.Maps;
|
|||
@Singleton
|
||||
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
|
||||
|
||||
private final String xmlTemplate;
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
private final BindToStringPayload stringBinder;
|
||||
protected final Map<String, String> defaultParams;
|
||||
protected final Map<ResourceType, String> defaultVirtualHardwareQuantity;
|
||||
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(
|
||||
ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
|
||||
|
||||
private final String defaultNetwork;
|
||||
|
||||
/**
|
||||
* To allow for optional injection, since guice doesn't allow unresolved constants in
|
||||
* constructors
|
||||
*/
|
||||
protected static class OptionalConstantsHolder {
|
||||
@Inject(optional = true)
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT)
|
||||
String cpuCount;
|
||||
@Inject(optional = true)
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_MEMORY)
|
||||
String memorySizeMegabytes;
|
||||
@Inject(optional = true)
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_DISK)
|
||||
String diskSizeKilobytes;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public BindInstantiateVAppTemplateParamsToXmlPayload(
|
||||
@Named("InstantiateVAppTemplateParams") String xmlTemplate,
|
||||
BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory) {
|
||||
this.xmlTemplate = xmlTemplate;
|
||||
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
|
||||
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
|
||||
OptionalConstantsHolder defaultsHolder) {
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
this.stringBinder = stringBinder;
|
||||
this.defaultParams = Maps.newHashMap();
|
||||
this.defaultParams.put("network", defaultNetwork);
|
||||
this.defaultParams.put("count", defaultCpuCount);
|
||||
this.defaultParams.put("megabytes", defaultMemory);
|
||||
this.defaultVirtualHardwareQuantity = Maps.newHashMap();
|
||||
this.defaultNetwork = network;
|
||||
if (defaultsHolder.cpuCount != null)
|
||||
this.defaultVirtualHardwareQuantity.put(ResourceType.PROCESSOR, defaultsHolder.cpuCount);
|
||||
if (defaultsHolder.memorySizeMegabytes != null)
|
||||
this.defaultVirtualHardwareQuantity.put(ResourceType.MEMORY,
|
||||
defaultsHolder.memorySizeMegabytes);
|
||||
if (defaultsHolder.diskSizeKilobytes != null)
|
||||
this.defaultVirtualHardwareQuantity.put(ResourceType.DISK_DRIVE,
|
||||
defaultsHolder.diskSizeKilobytes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -79,39 +116,153 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
|
|||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
|
||||
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
|
||||
postParams = new HashMap<String, String>(postParams);
|
||||
postParams.putAll(defaultParams);
|
||||
addOptionsToMap(postParams, gRequest);
|
||||
String name = checkNotNull(postParams.remove("name"), "name");
|
||||
String template = checkNotNull(postParams.remove("template"), "template");
|
||||
String network = postParams.remove("network");
|
||||
|
||||
String payload = xmlTemplate;
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity = extractVirtualQuantityFromPostParams(postParams);
|
||||
|
||||
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
|
||||
Map<String, String> properties = Maps.newTreeMap();
|
||||
if (options != null) {
|
||||
String networkFromOptions = addQuantityOrReturnNetwork(options, virtualHardwareQuantity,
|
||||
network);
|
||||
network = networkFromOptions != null ? networkFromOptions : network;
|
||||
properties.putAll(options.getProperties());
|
||||
}
|
||||
network = network == null ? defaultNetwork : network;
|
||||
try {
|
||||
stringBinder.bindToRequest(request, generateXml(name, template, properties,
|
||||
virtualHardwareQuantity, network));
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (FactoryConfigurationError e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (TransformerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected SortedMap<ResourceType, String> extractVirtualQuantityFromPostParams(
|
||||
Map<String, String> postParams) {
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
|
||||
virtualHardwareQuantity.putAll(defaultVirtualHardwareQuantity);
|
||||
for (Entry<String, String> entry : postParams.entrySet()) {
|
||||
payload = payload.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue());
|
||||
virtualHardwareQuantity.put(ResourceType.fromValue(entry.getKey()), entry.getValue());
|
||||
}
|
||||
stringBinder.bindToRequest(request, payload);
|
||||
return virtualHardwareQuantity;
|
||||
}
|
||||
|
||||
protected void addOptionsToMap(Map<String, String> postParams, GeneratedHttpRequest<?> gRequest) {
|
||||
protected String generateXml(String name, String template, Map<String, String> properties,
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity, String network)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
XMLBuilder rootBuilder = buildRoot(name);
|
||||
|
||||
rootBuilder.e("VAppTemplate").a("href", template);
|
||||
|
||||
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
|
||||
addPropertiesifPresent(instantiationParamsBuilder, properties);
|
||||
addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
|
||||
addNetworkConfig(instantiationParamsBuilder, name, network);
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
}
|
||||
|
||||
protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder,
|
||||
Map<String, String> properties) {
|
||||
if (properties.size() > 0) {
|
||||
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a(
|
||||
"xmlns:q1", "http://www.vmware.com/vcloud/v1").a("xmlns:ovf",
|
||||
"http://schemas.dmtf.org/ovf/envelope/1");
|
||||
for (Entry<String, String> entry : properties.entrySet()) {
|
||||
productSectionBuilder.e("Property")
|
||||
.a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
|
||||
entry.getKey()).a("ovf:value", entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name,
|
||||
String network) {
|
||||
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e(
|
||||
"NetworkConfig").a("name", name);
|
||||
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
|
||||
featuresBuilder.e("FenceMode").t("allowInOut");
|
||||
featuresBuilder.e("Dhcp").t("false");
|
||||
networkConfigBuilder.e("NetworkAssociation").a("href", network);
|
||||
}
|
||||
|
||||
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity) {
|
||||
if (virtualHardwareQuantity.size() > 0) {
|
||||
XMLBuilder virtualHardwareSectionBuilder = instantiationParamsBuilder.e(
|
||||
"VirtualHardwareSection").a("xmlns:q1", "http://www.vmware.com/vcloud/v1");
|
||||
for (Entry<ResourceType, String> entry : virtualHardwareQuantity.entrySet()) {
|
||||
XMLBuilder itemBuilder = virtualHardwareSectionBuilder.e("Item").a("xmlns",
|
||||
"http://schemas.dmtf.org/ovf/envelope/1");
|
||||
itemBuilder
|
||||
.e("InstanceID")
|
||||
.a("xmlns",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(virtualHardwareToInstanceId.get(entry.getKey()));
|
||||
itemBuilder
|
||||
.e("ResourceType")
|
||||
.a("xmlns",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(entry.getKey().value());
|
||||
itemBuilder
|
||||
.e("VirtualQuantity")
|
||||
.a("xmlns",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.t(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name)
|
||||
.a("xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
|
||||
"xsi:schemaLocation", ns + " " + schema);
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
|
||||
for (Object arg : gRequest.getArgs()) {
|
||||
if (arg instanceof InstantiateVAppTemplateOptions) {
|
||||
InstantiateVAppTemplateOptions options = (InstantiateVAppTemplateOptions) arg;
|
||||
if (options.getCpuCount() != null) {
|
||||
postParams.put("count", options.getCpuCount());
|
||||
return (InstantiateVAppTemplateOptions) arg;
|
||||
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
|
||||
InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg;
|
||||
return (options.length > 0) ? options[0] : null;
|
||||
}
|
||||
if (options.getMegabytes() != null) {
|
||||
postParams.put("megabytes", options.getMegabytes());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String addQuantityOrReturnNetwork(InstantiateVAppTemplateOptions options,
|
||||
Map<ResourceType, String> virtualHardwareQuantity, String network) {
|
||||
if (options.getCpuCount() != null) {
|
||||
virtualHardwareQuantity.put(ResourceType.PROCESSOR, options.getCpuCount());
|
||||
}
|
||||
if (options.getMemorySizeMegabytes() != null) {
|
||||
virtualHardwareQuantity.put(ResourceType.MEMORY, options.getMemorySizeMegabytes());
|
||||
}
|
||||
if (options.getDiskSizeKilobytes() != null) {
|
||||
virtualHardwareQuantity.put(ResourceType.DISK_DRIVE, options.getDiskSizeKilobytes());
|
||||
}
|
||||
if (options.getNetwork() != null) {
|
||||
postParams.put("network", options.getNetwork());
|
||||
}
|
||||
}
|
||||
return options.getNetwork();
|
||||
}
|
||||
return network;
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
|
||||
}
|
||||
|
||||
String ifNullDefaultTo(String value, String defaultValue) {
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,15 +23,13 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.config;
|
||||
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -216,14 +214,6 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
return org.getCatalog().getLocation();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Network
|
||||
@Singleton
|
||||
|
@ -234,7 +224,7 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@Provides
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK)
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
|
||||
@Singleton
|
||||
String provideDefaultNetworkString(@Network URI network) {
|
||||
return network.toASCIIString();
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.jclouds.vcloud.domain.internal.CatalogImpl;
|
||||
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(CatalogImpl.class)
|
||||
public interface CatalogItem extends NamedResource {
|
||||
|
||||
String getDescription();
|
||||
|
||||
NamedResource getEntity();
|
||||
|
||||
SortedMap<String, String> getProperties();
|
||||
|
||||
}
|
|
@ -21,19 +21,16 @@
|
|||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.reference;
|
||||
|
||||
import org.jclouds.vcloud.reference.VCloudConstants;
|
||||
package org.jclouds.vcloud.domain;
|
||||
|
||||
/**
|
||||
* Configuration properties and constants used in Terremark VCloud connections.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public interface TerremarkVCloudConstants extends VCloudConstants {
|
||||
public interface VAppTemplate extends NamedResource {
|
||||
|
||||
public static final String PROPERTY_TERREMARK_DEFAULTGROUP = "jclouds.terremark.defaults.group";
|
||||
public static final String PROPERTY_TERREMARK_DEFAULTROW = "jclouds.terremark.defaults.row";
|
||||
public static final String PROPERTY_TERREMARK_DEFAULTPASSWORD = "jclouds.terremark.defaults.password";
|
||||
VAppStatus getStatus();
|
||||
|
||||
String getDescription();
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.internal;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class CatalogItemImpl extends NamedResourceImpl implements CatalogItem {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final NamedResource entity;
|
||||
private final SortedMap<String, String> properties = Maps.newTreeMap();
|
||||
|
||||
public CatalogItemImpl(String id, String name, URI location, @Nullable String description,
|
||||
NamedResource entity, SortedMap<String, String> properties) {
|
||||
super(id, name, VCloudMediaType.CATALOGITEM_XML, location);
|
||||
this.description = description;
|
||||
this.entity = checkNotNull(entity, "entity");
|
||||
this.properties.putAll(checkNotNull(properties, "properties"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return VCloudMediaType.CATALOGITEM_XML;
|
||||
}
|
||||
|
||||
public NamedResource getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public SortedMap<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CatalogItemImpl [id=" + getId() + ", name=" + getName() + ", location="
|
||||
+ getLocation() + ", type=" + getType() + ", description=" + getDescription()
|
||||
+ ", entity=" + entity + ", properties=" + properties + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((entity == null) ? 0 : entity.hashCode());
|
||||
result = prime * result + ((properties == null) ? 0 : properties.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;
|
||||
CatalogItemImpl other = (CatalogItemImpl) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (entity == null) {
|
||||
if (other.entity != null)
|
||||
return false;
|
||||
} else if (!entity.equals(other.entity))
|
||||
return false;
|
||||
if (properties == null) {
|
||||
if (other.properties != null)
|
||||
return false;
|
||||
} else if (!properties.equals(other.properties))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.internal;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class VAppTemplateImpl extends NamedResourceImpl implements VAppTemplate {
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
private final String description;
|
||||
private final VAppStatus status;
|
||||
|
||||
public VAppTemplateImpl(String id, String name, URI location, @Nullable String description,
|
||||
@Nullable VAppStatus status) {
|
||||
super(id, name, VCloudMediaType.VAPPTEMPLATE_XML, location);
|
||||
this.description = description;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public VAppStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((status == null) ? 0 : status.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;
|
||||
VAppTemplateImpl other = (VAppTemplateImpl) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (status == null) {
|
||||
if (other.status != null)
|
||||
return false;
|
||||
} else if (!status.equals(other.status))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VAppTemplateImpl [description=" + description + ", status=" + status + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,9 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,18 +39,36 @@ import java.net.URI;
|
|||
public class InstantiateVAppTemplateOptions {
|
||||
|
||||
private String cpuCount;
|
||||
private String megabytes;
|
||||
private String memorySizeMegabytes;
|
||||
private String diskSizeKilobytes;
|
||||
private String network;
|
||||
private Map<String, String> properties = Maps.newTreeMap();
|
||||
|
||||
public InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
|
||||
public InstantiateVAppTemplateOptions productProperty(String key, String value) {
|
||||
properties.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public InstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
|
||||
this.properties.putAll(checkNotNull(properties, "properties"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public InstantiateVAppTemplateOptions processorCount(int cpuCount) {
|
||||
checkArgument(cpuCount >= 1, "cpuCount must be positive");
|
||||
this.cpuCount = cpuCount + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public InstantiateVAppTemplateOptions megabytes(int megabytes) {
|
||||
public InstantiateVAppTemplateOptions memory(long megabytes) {
|
||||
checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512");
|
||||
this.megabytes = megabytes + "";
|
||||
this.memorySizeMegabytes = megabytes + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public InstantiateVAppTemplateOptions disk(long kilobytes) {
|
||||
checkArgument(kilobytes >= 1, "diskSizeKilobytes must be positive");
|
||||
this.diskSizeKilobytes = kilobytes + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -60,30 +81,46 @@ public class InstantiateVAppTemplateOptions {
|
|||
return cpuCount;
|
||||
}
|
||||
|
||||
public String getMegabytes() {
|
||||
return megabytes;
|
||||
public String getMemorySizeMegabytes() {
|
||||
return memorySizeMegabytes;
|
||||
}
|
||||
|
||||
public String getDiskSizeKilobytes() {
|
||||
return diskSizeKilobytes;
|
||||
}
|
||||
|
||||
public String getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#cpuCount(int)
|
||||
* @see InstantiateVAppTemplateOptions#processorCount(int)
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
|
||||
public static InstantiateVAppTemplateOptions processorCount(int cpuCount) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.cpuCount(cpuCount);
|
||||
return options.processorCount(cpuCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#megabytes(int)
|
||||
* @see InstantiateVAppTemplateOptions#memory(int)
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions megabytes(int megabytes) {
|
||||
public static InstantiateVAppTemplateOptions memory(int megabytes) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.megabytes(megabytes);
|
||||
return options.memory(megabytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#disk(int)
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions disk(long kilobytes) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.disk(kilobytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,5 +130,22 @@ public class InstantiateVAppTemplateOptions {
|
|||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.inNetwork(networkLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#productProperty(String,String)
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions productProperty(String key, String value) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.productProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#setProperties(Map<String, String>)
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.productProperties(properties);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,8 +37,20 @@ public interface VCloudConstants {
|
|||
* automatically renew vcloud token before this interval expires.
|
||||
*/
|
||||
public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval";
|
||||
public static final String PROPERTY_VCLOUD_DEFAULTCPUCOUNT = "jclouds.vcloud.defaults.cpucount";
|
||||
public static final String PROPERTY_VCLOUD_DEFAULTMEMORY = "jclouds.vcloud.defaults.memory";
|
||||
public static final String PROPERTY_VCLOUD_DEFAULTNETWORK = "jclouds.vcloud.defaults.network";
|
||||
/**
|
||||
* cpus
|
||||
*/
|
||||
public static final String PROPERTY_VCLOUD_DEFAULT_CPUCOUNT = "jclouds.vcloud.defaults.cpucount";
|
||||
/**
|
||||
* megabytes
|
||||
*/
|
||||
public static final String PROPERTY_VCLOUD_DEFAULT_MEMORY = "jclouds.vcloud.defaults.memorysizemegabytes";
|
||||
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
|
||||
/**
|
||||
* kilobytes
|
||||
*/
|
||||
public static final String PROPERTY_VCLOUD_DEFAULT_DISK = "jclouds.vcloud.defaults.getdisksizekilobytes";
|
||||
public static final String PROPERTY_VCLOUD_XML_NAMESPACE = "jclouds.vcloud.xml.ns";
|
||||
public static final String PROPERTY_VCLOUD_XML_SCHEMA = "jclouds.vcloud.xml.schema";
|
||||
|
||||
}
|
||||
|
|
|
@ -23,18 +23,12 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.xml;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.internal.CatalogImpl;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.util.Utils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -49,9 +43,6 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
|
|||
|
||||
private NamedResource catalog;
|
||||
private SortedMap<String, NamedResource> contents = Maps.newTreeMap();
|
||||
@Inject
|
||||
@CatalogItemRoot
|
||||
private String catalogItemRoot;
|
||||
|
||||
private String description;
|
||||
|
||||
|
@ -66,7 +57,7 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
|
|||
if (qName.equals("Catalog")) {
|
||||
catalog = Utils.newNamedResource(attributes);
|
||||
} else if (qName.equals("CatalogItem")) {
|
||||
putNamedResource(contents, attributes);
|
||||
Utils.putNamedResource(contents, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,19 +72,6 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
|
|||
currentText.append(ch, start, length);
|
||||
}
|
||||
|
||||
public NamedResource newNamedResource(Attributes attributes) {
|
||||
String href = attributes.getValue(attributes.getIndex("href"));
|
||||
String id = href.replace(catalogItemRoot + "/", "");
|
||||
assert !id.contains("https://") : String.format(
|
||||
"parse of %s should have stripped, but didn't %s", href, id);
|
||||
return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes
|
||||
.getValue(attributes.getIndex("type")), URI.create(href));
|
||||
}
|
||||
|
||||
public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) {
|
||||
map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes));
|
||||
}
|
||||
|
||||
protected String currentOrNull() {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? null : returnVal;
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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;
|
||||
|
||||
import java.util.SortedMap;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
||||
import org.jclouds.vcloud.util.Utils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class CatalogItemHandler extends ParseSax.HandlerWithResult<CatalogItem> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private NamedResource catalog;
|
||||
private NamedResource entity;
|
||||
|
||||
private String description;
|
||||
private String key;
|
||||
private SortedMap<String, String> properties = Maps.newTreeMap();
|
||||
|
||||
public CatalogItem getResult() {
|
||||
return new CatalogItemImpl(catalog.getId(), catalog.getName(), catalog.getLocation(),
|
||||
description, entity, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
if (qName.equals("CatalogItem")) {
|
||||
catalog = Utils.newNamedResource(attributes);
|
||||
} else if (qName.equals("Entity")) {
|
||||
entity = Utils.newNamedResource(attributes);
|
||||
} else if (qName.equals("Property")) {
|
||||
key = attributes.getValue(attributes.getIndex("key"));
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("Description")) {
|
||||
description = currentOrNull();
|
||||
} else if (qName.equals("Property")) {
|
||||
properties.put(key, currentOrNull());
|
||||
key = null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
|
||||
import org.jclouds.vcloud.util.Utils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate> {
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private NamedResource catalog;
|
||||
private String description;
|
||||
private VAppStatus status;
|
||||
|
||||
public VAppTemplate getResult() {
|
||||
return new VAppTemplateImpl(catalog.getId(), catalog.getName(), catalog.getLocation(),
|
||||
description, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
if (qName.equals("VAppTemplate")) {
|
||||
catalog = Utils.newNamedResource(attributes);
|
||||
if (attributes.getIndex("status") != -1)
|
||||
status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("Description")) {
|
||||
description = currentOrNull();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<InstantiateVAppTemplateParams name="{name}"
|
||||
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd">
|
||||
<VAppTemplate href="{template}" />
|
||||
<InstantiationParams xmlns:vmw="http://www.vmware.com/schema/ovf">
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig name="{name}">
|
||||
<Features>
|
||||
<vmw:FenceMode>allowInOut</vmw:FenceMode>
|
||||
<vmw:Dhcp>false</vmw:Dhcp>
|
||||
</Features>
|
||||
<NetworkAssociation href="{network}" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
|
@ -23,11 +23,15 @@
|
|||
*/
|
||||
package org.jclouds.vcloud;
|
||||
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
|
@ -38,6 +42,8 @@ import org.jclouds.logging.Logger.LoggerFactory;
|
|||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Org;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
|
@ -45,12 +51,16 @@ import org.jclouds.vcloud.endpoints.VCloudApi;
|
|||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.CatalogItemHandler;
|
||||
import org.jclouds.vcloud.xml.OrgHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||
import org.jclouds.vcloud.xml.VAppHandler;
|
||||
import org.jclouds.vcloud.xml.VAppTemplateHandler;
|
||||
import org.jclouds.vcloud.xml.VDCHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -65,6 +75,54 @@ import com.google.inject.TypeLiteral;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
|
||||
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
||||
|
||||
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
|
||||
"CentOS 01", 3 + "");
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 636\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/newvapp-hosting.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, VAppHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testInstantiateVAppTemplateOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1",
|
||||
"CentOS 01", 3 + "", processorCount(1).memory(512).disk(1024)
|
||||
.inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990")));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Accept: application/vnd.vmware.vcloud.vApp+xml\nContent-Length: 2018\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/newvapp-hostingcpumemdisk.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, VAppHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getOrganization");
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
@ -95,6 +153,36 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testCatalogItem() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", String.class);
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/2 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CatalogItemHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", String.class);
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/vAppTemplate/2 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getDefaultVDC");
|
||||
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
|
@ -340,10 +428,16 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Properties props = new Properties();
|
||||
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
|
||||
"https://vcloud.safesecureweb.com/network/1990");
|
||||
Jsr330.bindProperties(binder(), new VCloudPropertiesBuilder(props).build());
|
||||
bind(URI.class).annotatedWith(Org.class).toInstance(URI.create("http://org"));
|
||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.toInstance("http://catalogItem");
|
||||
bind(String.class).annotatedWith(VAppTemplateRoot.class).toInstance(
|
||||
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate");
|
||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vApps");
|
||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
||||
bind(URI.class).annotatedWith(TasksList.class).toInstance(
|
||||
|
@ -364,7 +458,6 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.net.URI;
|
|||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.Organization;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
|
@ -71,6 +72,35 @@ public class VCloudClientLiveTest {
|
|||
assert response.size() > 0;
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testGetCatalogItem() throws Exception {
|
||||
Catalog response = connection.getCatalog();
|
||||
for (NamedResource resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getId());
|
||||
assertNotNull(item);
|
||||
assertNotNull(item.getEntity());
|
||||
assertNotNull(item.getId());
|
||||
assertNotNull(item.getLocation());
|
||||
assertNotNull(item.getProperties());
|
||||
assertNotNull(item.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testGetVAppTemplate() throws Exception {
|
||||
Catalog response = connection.getCatalog();
|
||||
for (NamedResource resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getId());
|
||||
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||
assertNotNull(connection.getVAppTemplate(item.getEntity().getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultVDC() throws Exception {
|
||||
VDC response = connection.getDefaultVDC();
|
||||
|
@ -99,9 +129,8 @@ public class VCloudClientLiveTest {
|
|||
assertNotNull(response);
|
||||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
for (Task t : response.getTasks()) {
|
||||
assertEquals(connection.getTask(t.getId()).getLocation(), t.getLocation());
|
||||
}
|
||||
Task task = response.getTasks().last();
|
||||
assertEquals(connection.getTask(task.getId()).getLocation(), task.getLocation());
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
|
|
|
@ -87,8 +87,8 @@ public class VCloudComputeClient {
|
|||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
|
||||
VApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(name, templateId, vDCId,
|
||||
InstantiateVAppTemplateOptions.Builder.processorCount(minCores).memory(minMegs));
|
||||
tmClient.getVApp(vAppResponse.getId());
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
|
||||
|
||||
|
|
|
@ -23,27 +23,23 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.VCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
@ -53,8 +49,6 @@ import com.google.common.collect.Multimaps;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlPayload}
|
||||
|
@ -67,41 +61,25 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider(
|
||||
Providers.<String> of("1"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
|
||||
Providers.<String> of("512"));
|
||||
bind(String.class)
|
||||
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||
.toProvider(
|
||||
Providers
|
||||
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
Properties props = new Properties();
|
||||
props
|
||||
.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
|
||||
"https://vcloud.safesecureweb.com/network/1990");
|
||||
Jsr330.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(),
|
||||
"properties"));
|
||||
}
|
||||
});
|
||||
|
||||
public void testApplyInputStream1() throws IOException {
|
||||
|
||||
public void testDefault() throws IOException {
|
||||
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/newvapp-hosting.xml"));
|
||||
Multimap<String, String> headers = Multimaps
|
||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
||||
.<String, String> create());
|
||||
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();
|
||||
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
|
||||
.atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expected);
|
||||
replay(request);
|
||||
|
@ -111,29 +89,22 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "CentOS 01");
|
||||
map.put("template",
|
||||
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||
map.put("count", "1");
|
||||
map.put("megabytes", "512");
|
||||
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
|
||||
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||
binder.bindToRequest(request, map);
|
||||
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
|
||||
.singletonList("application/unknown"));
|
||||
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||
.singletonList("901"));
|
||||
verify(request);
|
||||
|
||||
}
|
||||
|
||||
public void testApplyInputStream2() throws IOException {
|
||||
|
||||
public void testWithProcessorMemoryDisk() throws IOException {
|
||||
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/newvapp-hosting.xml"));
|
||||
Multimap<String, String> headers = Multimaps
|
||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||
"/newvapp-hostingcpumemdisk.xml"));
|
||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
||||
.<String, String> create());
|
||||
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();
|
||||
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null)
|
||||
.atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expected);
|
||||
replay(request);
|
||||
|
@ -143,13 +114,15 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "CentOS 01");
|
||||
map.put("template",
|
||||
"https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
|
||||
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
|
||||
|
||||
map.put(ResourceType.PROCESSOR.value(), "1");
|
||||
map.put(ResourceType.MEMORY.value(), "512");
|
||||
map.put(ResourceType.DISK_DRIVE.value(), "1024");
|
||||
|
||||
binder.bindToRequest(request, map);
|
||||
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
|
||||
.singletonList("application/unknown"));
|
||||
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||
.singletonList("901"));
|
||||
verify(request);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
|||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -45,7 +44,6 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
|||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient;
|
||||
import org.jclouds.vcloud.internal.VCloudLoginAsyncClient.VCloudSession;
|
||||
|
@ -55,7 +53,6 @@ import com.google.common.base.Supplier;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -79,15 +76,6 @@ public class VCloudRestClientModuleTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void postStrings() throws IOException {
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils
|
||||
.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/InstantiateVAppTemplateParams.xml")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
|
||||
VCloudRestClientModule module = new VCloudRestClientModule();
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.options;
|
||||
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.cpuCount;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.megabytes;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -62,31 +63,50 @@ public class InstantiateVAppTemplateOptionsTest {
|
|||
@Test
|
||||
public void testCpuCount() {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
options.cpuCount(3);
|
||||
options.processorCount(3);
|
||||
assertEquals(options.getCpuCount(), "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCpuCountStatic() {
|
||||
InstantiateVAppTemplateOptions options = cpuCount(3);
|
||||
InstantiateVAppTemplateOptions options = processorCount(3);
|
||||
assertEquals(options.getCpuCount(), "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMegabytes() {
|
||||
public void testRam() {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
options.megabytes(512);
|
||||
assertEquals(options.getMegabytes(), "512");
|
||||
options.memory(512);
|
||||
assertEquals(options.getMemorySizeMegabytes(), "512");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMegabytesStatic() {
|
||||
InstantiateVAppTemplateOptions options = megabytes(512);
|
||||
assertEquals(options.getMegabytes(), "512");
|
||||
public void testRamStatic() {
|
||||
InstantiateVAppTemplateOptions options = memory(512);
|
||||
assertEquals(options.getMemorySizeMegabytes(), "512");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testMegabytesStaticWrong() {
|
||||
megabytes(511);
|
||||
public void testRamStaticWrong() {
|
||||
memory(511);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisk() {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
options.disk(512);
|
||||
assertEquals(options.getDiskSizeKilobytes(), "512");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiskStatic() {
|
||||
InstantiateVAppTemplateOptions options = disk(512);
|
||||
assertEquals(options.getDiskSizeKilobytes(), "512");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testDiskStaticWrong() {
|
||||
disk(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.xml;
|
||||
|
||||
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -32,15 +31,14 @@ import java.net.URI;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CatalogHandler}
|
||||
|
@ -50,155 +48,21 @@ import com.google.inject.Provides;
|
|||
@Test(groups = "unit", testName = "vcloud.CatalogHandlerTest")
|
||||
public class CatalogHandlerTest {
|
||||
|
||||
private Injector injector;
|
||||
|
||||
private Factory factory;
|
||||
|
||||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/catalog.xml");
|
||||
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
InputStream is = getClass().getResourceAsStream("/catalogItem-hosting.xml");
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||
CatalogItem result = factory.create(injector.getInstance(CatalogItemHandler.class)).parse(is);
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
assertEquals(result, new CatalogItemImpl("2", "Windows 2008 Datacenter 64 Bit", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"),
|
||||
"Windows 2008 Datacenter 64 Bit", new NamedResourceImpl("2",
|
||||
"Windows 2008 Datacenter 64 Bit",
|
||||
"application/vnd.vmware.vcloud.vAppTemplate+xml",
|
||||
URI.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")),
|
||||
ImmutableSortedMap.of("Foo", "Bar", "Hello", "World"
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
String provide() {
|
||||
return "https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem";
|
||||
}
|
||||
)));
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getName(), "Miami Environment 1");
|
||||
assert result.getDescription() == null;
|
||||
|
||||
assertEquals(result.getLocation(), URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
|
||||
|
||||
assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "",
|
||||
"CentOS 5.3 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5")));
|
||||
assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "",
|
||||
"CentOS 5.3 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6")));
|
||||
assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "",
|
||||
"RHEL 5.3 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7")));
|
||||
assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "",
|
||||
"RHEL 5.3 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8")));
|
||||
assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "",
|
||||
"Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11")));
|
||||
assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "",
|
||||
"Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12")));
|
||||
assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "",
|
||||
"Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9")));
|
||||
assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "",
|
||||
"Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10")));
|
||||
assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "",
|
||||
"Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1")));
|
||||
assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "",
|
||||
"Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2")));
|
||||
assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "",
|
||||
"Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3")));
|
||||
assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "",
|
||||
"Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4")));
|
||||
assertEquals(
|
||||
result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"),
|
||||
new NamedResourceImpl(
|
||||
23 + "",
|
||||
"Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)",
|
||||
CATALOGITEM_XML,
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl(
|
||||
13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl(
|
||||
15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl(
|
||||
16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl(
|
||||
17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl(
|
||||
18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl(
|
||||
19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19")));
|
||||
assertEquals(
|
||||
result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"),
|
||||
new NamedResourceImpl(
|
||||
14 + "",
|
||||
"Windows Server 2008 Standard w.SQL 2008 Web (64-bit)",
|
||||
CATALOGITEM_XML,
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14")));
|
||||
assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "",
|
||||
"Windows Web Server 2008 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20")));
|
||||
assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "",
|
||||
"Windows Web Server 2008 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21")));
|
||||
assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl(
|
||||
22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22")));
|
||||
|
||||
}
|
||||
|
||||
public void testHosting() {
|
||||
InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml");
|
||||
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
String provide() {
|
||||
return "https://vcloud.safesecureweb.com/api/v0.8/catalogItem";
|
||||
}
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getName(), "HMSCatalog");
|
||||
assertEquals(result.getDescription(), "HMS Shared Catalog");
|
||||
assertEquals(result.getLocation(), URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
|
||||
|
||||
assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "",
|
||||
"Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")));
|
||||
|
||||
assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(
|
||||
2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")));
|
||||
|
||||
assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "",
|
||||
"Cent OS 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3")));
|
||||
|
||||
assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "",
|
||||
"cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4")));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CatalogHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.CatalogHandlerTest")
|
||||
public class CatalogItemHandlerTest {
|
||||
|
||||
private Injector injector;
|
||||
|
||||
private Factory factory;
|
||||
|
||||
public void testApplyInputStream() {
|
||||
InputStream is = getClass().getResourceAsStream("/catalog.xml");
|
||||
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
String provide() {
|
||||
return "https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem";
|
||||
}
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getName(), "Miami Environment 1");
|
||||
assert result.getDescription() == null;
|
||||
|
||||
assertEquals(result.getLocation(), URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
|
||||
|
||||
assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5 + "",
|
||||
"CentOS 5.3 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5")));
|
||||
assertEquals(result.get("CentOS 5.3 (64-bit)"), new NamedResourceImpl(6 + "",
|
||||
"CentOS 5.3 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6")));
|
||||
assertEquals(result.get("RHEL 5.3 (32-bit)"), new NamedResourceImpl(7 + "",
|
||||
"RHEL 5.3 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7")));
|
||||
assertEquals(result.get("RHEL 5.3 (64-bit)"), new NamedResourceImpl(8 + "",
|
||||
"RHEL 5.3 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8")));
|
||||
assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new NamedResourceImpl(11 + "",
|
||||
"Ubuntu JeOS 9.04 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11")));
|
||||
assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new NamedResourceImpl(12 + "",
|
||||
"Ubuntu JeOS 9.04 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12")));
|
||||
assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new NamedResourceImpl(9 + "",
|
||||
"Ubuntu Server 9.04 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9")));
|
||||
assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new NamedResourceImpl(10 + "",
|
||||
"Ubuntu Server 9.04 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10")));
|
||||
assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new NamedResourceImpl(1 + "",
|
||||
"Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1")));
|
||||
assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new NamedResourceImpl(2 + "",
|
||||
"Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2")));
|
||||
assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new NamedResourceImpl(3 + "",
|
||||
"Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3")));
|
||||
assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new NamedResourceImpl(4 + "",
|
||||
"Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4")));
|
||||
assertEquals(
|
||||
result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"),
|
||||
new NamedResourceImpl(
|
||||
23 + "",
|
||||
"Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)",
|
||||
CATALOGITEM_XML,
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new NamedResourceImpl(
|
||||
13 + "", "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new NamedResourceImpl(
|
||||
15 + "", "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15")));
|
||||
assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new NamedResourceImpl(
|
||||
16 + "", "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new NamedResourceImpl(
|
||||
17 + "", "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new NamedResourceImpl(
|
||||
18 + "", "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18")));
|
||||
assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new NamedResourceImpl(
|
||||
19 + "", "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19")));
|
||||
assertEquals(
|
||||
result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"),
|
||||
new NamedResourceImpl(
|
||||
14 + "",
|
||||
"Windows Server 2008 Standard w.SQL 2008 Web (64-bit)",
|
||||
CATALOGITEM_XML,
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14")));
|
||||
assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new NamedResourceImpl(20 + "",
|
||||
"Windows Web Server 2008 (32-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20")));
|
||||
assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new NamedResourceImpl(21 + "",
|
||||
"Windows Web Server 2008 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21")));
|
||||
assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new NamedResourceImpl(
|
||||
22 + "", "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML,
|
||||
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22")));
|
||||
|
||||
}
|
||||
|
||||
public void testHosting() {
|
||||
InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml");
|
||||
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@CatalogItemRoot
|
||||
String provide() {
|
||||
return "https://vcloud.safesecureweb.com/api/v0.8/catalogItem";
|
||||
}
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getName(), "HMSCatalog");
|
||||
assertEquals(result.getDescription(), "HMS Shared Catalog");
|
||||
assertEquals(result.getLocation(), URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"));
|
||||
|
||||
assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1 + "",
|
||||
"Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1")));
|
||||
|
||||
assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(
|
||||
2 + "", "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2")));
|
||||
|
||||
assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3 + "",
|
||||
"Cent OS 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3")));
|
||||
|
||||
assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4 + "",
|
||||
"cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4")));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||
import org.jclouds.vcloud.domain.internal.VAppTemplateImpl;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VAppTemplateHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.VAppTemplateHandlerTest")
|
||||
public class VAppTemplateHandlerTest {
|
||||
|
||||
private Injector injector;
|
||||
|
||||
private Factory factory;
|
||||
|
||||
public void testTerremark() {
|
||||
InputStream is = getClass().getResourceAsStream("/vAppTemplate-trmk.xml");
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result, new VAppTemplateImpl("5", "CentOS 5.3 (32-bit)", URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vAppTemplate/5"),
|
||||
"description of CentOS 5.3 (32-bit)", null));
|
||||
}
|
||||
|
||||
public void testHosting() {
|
||||
InputStream is = getClass().getResourceAsStream("/vAppTemplate-hosting.xml");
|
||||
injector = Guice.createInjector(new ParserModule());
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VAppTemplate result = (VAppTemplate) factory.create(
|
||||
injector.getInstance(VAppTemplateHandler.class)).parse(is);
|
||||
assertEquals(result, new VAppTemplateImpl("4", "cPanel (Linux) 64 Bit", URI
|
||||
.create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"),
|
||||
"cPanel (Linux) 64 Bit", VAppStatus.RESOLVED));
|
||||
}
|
||||
}
|
|
@ -1,17 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<InstantiateVAppTemplateParams name="CentOS 01"
|
||||
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd">
|
||||
<VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3" />
|
||||
<InstantiationParams xmlns:vmw="http://www.vmware.com/schema/ovf">
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig name="CentOS 01">
|
||||
<Features>
|
||||
<vmw:FenceMode>allowInOut</vmw:FenceMode>
|
||||
<vmw:Dhcp>false</vmw:Dhcp>
|
||||
</Features>
|
||||
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
||||
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="CentOS 01" xsi:schemaLocation="http://www.vmware.com/vcloud/0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"/><InstantiationParams><NetworkConfigSection><NetworkConfig name="CentOS 01"><Features><FenceMode>allowInOut</FenceMode><Dhcp>false</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
|
|
@ -87,8 +87,8 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@XMLResponseParser(HostingDotComVAppHandler.class)
|
||||
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
@Override
|
||||
Future<? extends HostingDotComVApp> instantiateVAppTemplate(
|
||||
@MapPayloadParam("name") String appName,
|
||||
Future<? extends HostingDotComVApp> instantiateVAppTemplateInVDC(
|
||||
@PathParam("vDCId") String vDCId, @MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public interface HostingDotComVCloudClient extends VCloudClient {
|
|||
|
||||
@Override
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
HostingDotComVApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -66,14 +66,18 @@ public class HostingDotComVCloudComputeClient {
|
|||
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(
|
||||
Image.UMBUNTU_JEOS, "11").build();
|
||||
|
||||
public Map<String, String> start(String name, int minCores, int minMegs, Image image) {
|
||||
public Map<String, String> start(String name, Image image, int minCores, int minMegs,
|
||||
long diskSize, Map<String, String> properties) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
String templateId = imageCatalogIdMap.get(image);
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
|
||||
logger
|
||||
.debug(
|
||||
">> instantiating vApp vDC(%s) name(%s) template(%s) minCores(%d) minMegs(%d) diskSize(%d) properties(%s) ",
|
||||
vDCId, name, templateId, minCores, minMegs, diskSize, properties);
|
||||
HostingDotComVApp vAppResponse = tmClient.instantiateVAppTemplateInVDC(vDCId, name,
|
||||
templateId, InstantiateVAppTemplateOptions.Builder.processorCount(minCores)
|
||||
.memory(minMegs).disk(diskSize).productProperties(properties));
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
|
||||
|
||||
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
|
||||
|
@ -113,7 +117,8 @@ public class HostingDotComVCloudComputeClient {
|
|||
public void stop(String id) {
|
||||
VApp vApp = tmClient.getVApp(id);
|
||||
if (vApp.getStatus() != VAppStatus.OFF) {
|
||||
logger.debug(">> powering off vApp(%s)", vApp.getId());
|
||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp
|
||||
.getStatus());
|
||||
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
|
||||
"powerOff", VAppStatus.OFF);
|
||||
logger.debug("<< off vApp(%s)", vApp.getId());
|
||||
|
|
|
@ -81,7 +81,8 @@ public class HostingDotComVCloudComputeService implements ComputeService {
|
|||
|
||||
@Override
|
||||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
Map<String, String> metaMap = computeClient.start(name, 1, 512, image);
|
||||
Map<String, String> metaMap = computeClient.start(name, image, 1, 512, (10l * 1025 * 1024),
|
||||
ImmutableMap.<String, String> of());
|
||||
VApp vApp = hostingClient.getVApp(metaMap.get("id"));
|
||||
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState
|
||||
.get(vApp.getStatus()), vApp.getNetworkToAddresses().values(), ImmutableSet
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.testng.annotations.AfterTest;
|
|||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -94,8 +95,10 @@ public class HostingDotComVCloudComputeClientLiveTest {
|
|||
String serverName = getCompatibleServerName(toTest);
|
||||
int processorCount = 1;
|
||||
int memory = 512;
|
||||
long disk = 10 * 1025 * 1024;
|
||||
Map<String, String> properties = ImmutableMap.of("foo", "bar");
|
||||
|
||||
id = client.start(serverName, processorCount, memory, toTest).get("id");
|
||||
id = client.start(serverName, toTest, processorCount, memory, disk, properties).get("id");
|
||||
Expectation expectation = expectationMap.get(toTest);
|
||||
|
||||
VApp vApp = tmClient.getVApp(id);
|
||||
|
@ -105,7 +108,8 @@ public class HostingDotComVCloudComputeClientLiveTest {
|
|||
}
|
||||
|
||||
private String getCompatibleServerName(Image toTest) {
|
||||
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
|
||||
String serverName = CaseFormat.UPPER_UNDERSCORE
|
||||
.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0,
|
||||
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
|
||||
return serverName;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,11 @@
|
|||
<module>hostingdotcom</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jamesmurty.utils</groupId>
|
||||
<artifactId>java-xmlbuilder</artifactId>
|
||||
<version>0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-jsch</artifactId>
|
||||
|
|
|
@ -53,7 +53,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
|||
import org.jclouds.vcloud.functions.CatalogIdToUri;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
|
@ -113,20 +113,21 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
@XMLResponseParser(TerremarkVAppHandler.class)
|
||||
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
@Override
|
||||
Future<? extends TerremarkVApp> instantiateVAppTemplate(@MapPayloadParam("name") String appName,
|
||||
Future<? extends TerremarkVApp> instantiateVAppTemplateInVDC(@PathParam("vDCId") String vDCId,
|
||||
@MapPayloadParam("name") String appName,
|
||||
@MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
|
||||
@PathParam("vDCId") String vDCId, InstantiateVAppTemplateOptions... options);
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#addInternetService
|
||||
*/
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/internetServices")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/internetServices")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
Future<? extends InternetService> addInternetService(
|
||||
Future<? extends InternetService> addInternetServiceToVDC(@PathParam("vDCId") String vDCId,
|
||||
@MapPayloadParam("name") String serviceName,
|
||||
@MapPayloadParam("protocol") Protocol protocol, @MapPayloadParam("port") int port,
|
||||
AddInternetServiceOptions... options);
|
||||
|
@ -135,10 +136,11 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
* @see TerremarkVCloudClient#getAllInternetServices
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/internetServices")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/internetServices")
|
||||
@XMLResponseParser(InternetServicesHandler.class)
|
||||
Future<? extends SortedSet<InternetService>> getAllInternetServices();
|
||||
Future<? extends SortedSet<InternetService>> getAllInternetServicesInVDC(
|
||||
@PathParam("vDCId") String vDCId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#addInternetServiceToExistingIp
|
||||
|
@ -159,7 +161,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
*/
|
||||
@DELETE
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/PublicIps/{ipId}")
|
||||
@Path("/publicIps/{ipId}")
|
||||
@ExceptionParser(ReturnVoidOnDeleteDefaultIp.class)
|
||||
Future<Void> deletePublicIp(@PathParam("ipId") int ipId);
|
||||
|
||||
|
@ -177,10 +179,11 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
* @see TerremarkVCloudClient#getPublicIpsAssociatedWithVDC
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/publicIps")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vdc/{vDCId}/publicIps")
|
||||
@XMLResponseParser(PublicIpAddressesHandler.class)
|
||||
Future<? extends SortedSet<PublicIpAddress>> getPublicIpsAssociatedWithVDC();
|
||||
Future<? extends SortedSet<PublicIpAddress>> getPublicIpsAssociatedWithVDC(
|
||||
@PathParam("vDCId") String vDCId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#deleteInternetService
|
||||
|
@ -253,21 +256,42 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
|
|||
Future<? extends TerremarkVApp> getVApp(@PathParam("vAppId") String vAppId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getComputeOptions
|
||||
* @see TerremarkVCloudClient#getComputeOptionsOfVApp
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/options/compute")
|
||||
@XMLResponseParser(ComputeOptionsHandler.class)
|
||||
Future<? extends SortedSet<ComputeOption>> getComputeOptions(@PathParam("vAppId") String vAppId);
|
||||
Future<? extends SortedSet<ComputeOptions>> getComputeOptionsOfVApp(
|
||||
@PathParam("vAppId") String vAppId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getCustomizationOptions
|
||||
* @see TerremarkVCloudClient#getCustomizationOptionsOfVApp
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/vapp/{vAppId}/options/customization")
|
||||
@XMLResponseParser(CustomizationParametersHandler.class)
|
||||
Future<? extends CustomizationParameters> getCustomizationOptions(
|
||||
Future<? extends CustomizationParameters> getCustomizationOptionsOfVApp(
|
||||
@PathParam("vAppId") String vAppId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getComputeOptionsOfCatalogItem
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalogItem/{catalogItemId}/options/compute")
|
||||
@XMLResponseParser(ComputeOptionsHandler.class)
|
||||
Future<? extends SortedSet<ComputeOptions>> getComputeOptionsOfCatalogItem(
|
||||
@PathParam("catalogItemId") String catalogItemId);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudClient#getCustomizationOptionsOfCatalogItem
|
||||
*/
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
|
||||
@Path("/catalogItem/{catalogItemId}/options/customization")
|
||||
@XMLResponseParser(CustomizationParametersHandler.class)
|
||||
Future<? extends CustomizationParameters> getCustomizationOptionsOfCatalogItem(
|
||||
@PathParam("catalogItemId") String catalogItemId);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
|
@ -51,7 +51,7 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
|||
public interface TerremarkVCloudClient extends VCloudClient {
|
||||
|
||||
@Override
|
||||
TerremarkVApp instantiateVAppTemplate(String appName, String templateId, String vDCId,
|
||||
TerremarkVApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@Override
|
||||
|
@ -62,19 +62,23 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
* configurations supported by Terremark and by the guest operating system of the vApp. This call
|
||||
* also returns the cost per hour for each configuration.
|
||||
*/
|
||||
SortedSet<ComputeOption> getComputeOptions(String vAppId);
|
||||
SortedSet<ComputeOptions> getComputeOptionsOfVApp(String vAppId);
|
||||
|
||||
SortedSet<ComputeOptions> getComputeOptionsOfCatalogItem(String catalogItemId);
|
||||
|
||||
/**
|
||||
* This call returns the customization options for the vApp. The response lists which
|
||||
* customization options are supported for this particular vApp. The possible customization
|
||||
* options are Network and Password.
|
||||
*/
|
||||
CustomizationParameters getCustomizationOptions(String vAppId);
|
||||
CustomizationParameters getCustomizationOptionsOfVApp(String vAppId);
|
||||
|
||||
CustomizationParameters getCustomizationOptionsOfCatalogItem(String catalogItemId);
|
||||
|
||||
/**
|
||||
* This call returns a list of public IP addresses.
|
||||
*/
|
||||
SortedSet<PublicIpAddress> getPublicIpsAssociatedWithVDC();
|
||||
SortedSet<PublicIpAddress> getPublicIpsAssociatedWithVDC(String vDCId);
|
||||
|
||||
void deletePublicIp(int ipId);
|
||||
|
||||
|
@ -82,25 +86,14 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
* The call creates a new internet server, including protocol and port information. The public IP
|
||||
* is dynamically allocated.
|
||||
*
|
||||
* @param serviceName
|
||||
* @param protocol
|
||||
* @param port
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
InternetService addInternetService(String serviceName, Protocol protocol, int port,
|
||||
AddInternetServiceOptions... options);
|
||||
InternetService addInternetServiceToVDC(String vDCId, String serviceName, Protocol protocol,
|
||||
int port, AddInternetServiceOptions... options);
|
||||
|
||||
/**
|
||||
* This call adds an internet service to a known, existing public IP. This call is identical to
|
||||
* Add Internet Service except you specify the public IP in the request.
|
||||
*
|
||||
* @param existingIpId
|
||||
* @param serviceName
|
||||
* @param protocol
|
||||
* @param port
|
||||
* @param options
|
||||
* @return
|
||||
*/
|
||||
InternetService addInternetServiceToExistingIp(int existingIpId, String serviceName,
|
||||
Protocol protocol, int port, AddInternetServiceOptions... options);
|
||||
|
@ -109,7 +102,7 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
|
||||
InternetService getInternetService(int internetServiceId);
|
||||
|
||||
SortedSet<InternetService> getAllInternetServices();
|
||||
SortedSet<InternetService> getAllInternetServicesInVDC(String vDCId);
|
||||
|
||||
/**
|
||||
* This call returns information about the internet service on a public IP.
|
||||
|
|
|
@ -23,10 +23,10 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
@ -42,9 +42,9 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
|
|||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_TERREMARK_DEFAULTGROUP, "group");
|
||||
properties.setProperty(PROPERTY_TERREMARK_DEFAULTROW, "row");
|
||||
properties.setProperty((PROPERTY_TERREMARK_DEFAULTPASSWORD), "password");
|
||||
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT, "1");
|
||||
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_MEMORY, "512");
|
||||
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v1");
|
||||
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT,
|
||||
"https://services.vcloudexpress.terremark.com/api");
|
||||
return properties;
|
||||
|
@ -55,7 +55,6 @@ public class TerremarkVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
|
|||
}
|
||||
|
||||
public TerremarkVCloudPropertiesBuilder(String id, String secret) {
|
||||
super(URI.create("https://services.vcloudexpress.terremark.com/api"),
|
||||
id, secret);
|
||||
super(URI.create("https://services.vcloudexpress.terremark.com/api"), id, secret);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,23 +23,27 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -51,37 +55,36 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
|
|||
BindInstantiateVAppTemplateParamsToXmlPayload {
|
||||
|
||||
@Inject
|
||||
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(
|
||||
@Named("InstantiateVAppTemplateParams") String xmlTemplate,
|
||||
BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory,
|
||||
@Named(PROPERTY_TERREMARK_DEFAULTGROUP) String defaultGroup,
|
||||
@Named(PROPERTY_TERREMARK_DEFAULTROW) String defaultRow,
|
||||
@Named(PROPERTY_TERREMARK_DEFAULTPASSWORD) String defaultPassword) {
|
||||
super(xmlTemplate, stringBinder, defaultNetwork, defaultCpuCount, defaultMemory);
|
||||
this.defaultParams.put("group", defaultGroup);
|
||||
this.defaultParams.put("row", defaultRow);
|
||||
this.defaultParams.put("password", defaultPassword);
|
||||
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
|
||||
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
|
||||
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
|
||||
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
|
||||
OptionalConstantsHolder optionalDefaults) {
|
||||
super(stringBinder, ns, schema, network, optionalDefaults);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addOptionsToMap(Map<String, String> postParams, GeneratedHttpRequest<?> gRequest) {
|
||||
super.addOptionsToMap(postParams, gRequest);
|
||||
for (Object arg : gRequest.getArgs()) {
|
||||
if (arg instanceof TerremarkInstantiateVAppTemplateOptions) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = (TerremarkInstantiateVAppTemplateOptions) arg;
|
||||
if (options.getGroup() != null) {
|
||||
postParams.put("group", options.getGroup());
|
||||
}
|
||||
if (options.getRow() != null) {
|
||||
postParams.put("row", options.getRow());
|
||||
}
|
||||
if (options.getPassword() != null) {
|
||||
postParams.put("password", options.getPassword());
|
||||
}
|
||||
protected String generateXml(String name, String template, Map<String, String> properties,
|
||||
SortedMap<ResourceType, String> virtualHardwareQuantity, String network)
|
||||
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
|
||||
checkNotNull(virtualHardwareQuantity.get(ResourceType.PROCESSOR),
|
||||
"cpuCount must be present in instantiateVapp on terremark");
|
||||
checkNotNull(virtualHardwareQuantity.get(ResourceType.MEMORY),
|
||||
"memorySizeMegabytes must be present in instantiateVapp on terremark");
|
||||
checkArgument(virtualHardwareQuantity.get(ResourceType.DISK_DRIVE) == null,
|
||||
"diskSizeKilobytes no settable on instantiateVapp on terremark");
|
||||
return super.generateXml(name, template, properties, virtualHardwareQuantity, network);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addPropertiesifPresent(XMLBuilder instantiationParamsBuilder,
|
||||
Map<String, String> properties) {
|
||||
if (properties.size() == 0) { // terremark requires the product section.
|
||||
instantiationParamsBuilder.e("ProductSection").a("xmlns:q1",
|
||||
"http://www.vmware.com/vcloud/v1").a("xmlns:ovf",
|
||||
"http://schemas.dmtf.org/ovf/envelope/1");
|
||||
} else {
|
||||
super.addPropertiesifPresent(instantiationParamsBuilder, properties);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import javax.inject.Inject;
|
|||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
|
@ -75,15 +74,15 @@ public class TerremarkVCloudComputeClient {
|
|||
Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(
|
||||
Image.UMBUNTU_JEOS, "11").build();
|
||||
|
||||
public String start(String name, int minCores, int minMegs, Image image) {
|
||||
public String start(String name, Image image, int minCores, int minMegs, Map<String, String> properties) {
|
||||
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
|
||||
String templateId = imageCatalogIdMap.get(image);
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s) vDC(%s)",
|
||||
name, minCores, minMegs, templateId, vDCId);
|
||||
TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, vDCId,
|
||||
TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores)
|
||||
.megabytes(minMegs));
|
||||
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) minCores(%d) minMegs(%d) properties(%s)",vDCId, templateId,
|
||||
name, minCores, minMegs, properties);
|
||||
TerremarkVApp vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, name, templateId,
|
||||
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(minCores)
|
||||
.memory(minMegs).productProperties(properties));
|
||||
logger.debug("<< instantiated VApp(%s)", vApp.getId());
|
||||
|
||||
logger.debug(">> deploying vApp(%s)", vApp.getId());
|
||||
|
@ -117,7 +116,7 @@ public class TerremarkVCloudComputeClient {
|
|||
logger.debug("<< on vApp(%s)", vApp.getId());
|
||||
}
|
||||
|
||||
public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) {
|
||||
public InetAddress createPublicAddressMappedToPorts(TerremarkVApp vApp, int... ports) {
|
||||
PublicIpAddress ip = null;
|
||||
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
|
||||
for (int port : ports) {
|
||||
|
@ -136,8 +135,10 @@ public class TerremarkVCloudComputeClient {
|
|||
|
||||
}
|
||||
if (ip == null) {
|
||||
logger.debug(">> creating InternetService %d", port);
|
||||
is = tmClient.addInternetService(vApp.getName() + "-" + port, protocol, port,
|
||||
logger.debug(">> creating InternetService in vDC %s; port %d", vApp.getVDC().getId(),
|
||||
port);
|
||||
is = tmClient.addInternetServiceToVDC(vApp.getVDC().getId(), vApp.getName() + "-"
|
||||
+ port, protocol, port,
|
||||
withDescription(String.format("port %d access to serverId: %s name: %s", port,
|
||||
vApp.getId(), vApp.getName())));
|
||||
ip = is.getPublicIpAddress();
|
||||
|
@ -167,7 +168,8 @@ public class TerremarkVCloudComputeClient {
|
|||
deletePublicIpAddressesWithNoServicesAttached(ipAddresses);
|
||||
|
||||
if (vApp.getStatus() != VAppStatus.OFF) {
|
||||
logger.debug(">> powering off vApp(%s)", vApp.getId());
|
||||
logger.debug(">> powering off vApp(%s), current status: %s", vApp.getId(), vApp
|
||||
.getStatus());
|
||||
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
|
||||
"powerOff", VAppStatus.OFF);
|
||||
logger.debug("<< off vApp(%s)", vApp.getId());
|
||||
|
@ -179,7 +181,8 @@ public class TerremarkVCloudComputeClient {
|
|||
|
||||
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) {
|
||||
Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
|
||||
SERVICE: for (InternetService service : tmClient.getAllInternetServices()) {
|
||||
SERVICE: for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC()
|
||||
.getId())) {
|
||||
for (Node node : tmClient.getNodes(service.getId())) {
|
||||
if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) {
|
||||
ipAddresses.add(service.getPublicIpAddress());
|
||||
|
|
|
@ -49,7 +49,7 @@ import org.jclouds.vcloud.domain.NamedResource;
|
|||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -83,8 +83,8 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
|
||||
@Override
|
||||
public CreateServerResponse createServer(String name, Profile profile, Image image) {
|
||||
String id = computeClient.start(name, 1, 512, image);
|
||||
VApp vApp = tmClient.getVApp(id);
|
||||
String id = computeClient.start(name, image, 1, 512, ImmutableMap.<String, String> of());
|
||||
TerremarkVApp vApp = tmClient.getVApp(id);
|
||||
// bug creating more than one internet service returns 503 or 500
|
||||
// InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22, 80, 8080);
|
||||
InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22);
|
||||
|
@ -104,16 +104,6 @@ public class TerremarkVCloudComputeService implements ComputeService {
|
|||
LoginType.SSH);
|
||||
}
|
||||
|
||||
public SortedSet<InternetService> getInternetServicesByName(final String name) {
|
||||
return Sets.newTreeSet(Iterables.filter(tmClient.getAllInternetServices(),
|
||||
new Predicate<InternetService>() {
|
||||
@Override
|
||||
public boolean apply(InternetService input) {
|
||||
return input.getName().equalsIgnoreCase(name);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<ServerIdentity> getServerByName(final String name) {
|
||||
return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate<ServerIdentity>() {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
package org.jclouds.vcloud.terremark.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -102,13 +101,6 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
|
|||
return SyncProxy.create(TerremarkVCloudClient.class, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
|
|
|
@ -32,12 +32,12 @@ package org.jclouds.vcloud.terremark.domain;
|
|||
* href="https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/6-using-the-vcloud-express-api.aspx"
|
||||
* >Terremark documentation</a>
|
||||
*/
|
||||
public class ComputeOption implements Comparable<ComputeOption> {
|
||||
public class ComputeOptions implements Comparable<ComputeOptions> {
|
||||
private final int processorCount;
|
||||
private final long memory;
|
||||
private final float costPerHour;
|
||||
|
||||
public ComputeOption(int processorCount, long memory, float costPerHour) {
|
||||
public ComputeOptions(int processorCount, long memory, float costPerHour) {
|
||||
this.processorCount = processorCount;
|
||||
this.memory = memory;
|
||||
this.costPerHour = costPerHour;
|
||||
|
@ -56,25 +56,14 @@ public class ComputeOption implements Comparable<ComputeOption> {
|
|||
}
|
||||
|
||||
/**
|
||||
* orders processor, memory, then cost.
|
||||
* orders by cost
|
||||
*/
|
||||
public int compareTo(ComputeOption that) {
|
||||
public int compareTo(ComputeOptions that) {
|
||||
if (this == that)
|
||||
return 0;
|
||||
double compareThis = compare(this);
|
||||
double compareThat = compare(that);
|
||||
if (compareThis < compareThat)
|
||||
if (this.costPerHour < that.costPerHour)
|
||||
return -1;
|
||||
if (compareThis > compareThat)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private double compare(ComputeOption option) {
|
||||
double comparison = processorCount * 20000;
|
||||
comparison += memory;
|
||||
comparison += costPerHour;
|
||||
return comparison;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,7 +84,7 @@ public class ComputeOption implements Comparable<ComputeOption> {
|
|||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ComputeOption other = (ComputeOption) obj;
|
||||
ComputeOptions other = (ComputeOptions) obj;
|
||||
if (Float.floatToIntBits(costPerHour) != Float.floatToIntBits(other.costPerHour))
|
||||
return false;
|
||||
if (memory != other.memory)
|
|
@ -41,11 +41,11 @@ public class CustomizationParameters {
|
|||
this.customizePassword = customizePassword;
|
||||
}
|
||||
|
||||
public boolean isCustomizeNetwork() {
|
||||
public boolean canCustomizeNetwork() {
|
||||
return customizeNetwork;
|
||||
}
|
||||
|
||||
public boolean isCustomizePassword() {
|
||||
public boolean canCustomizePassword() {
|
||||
return customizePassword;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
|
@ -34,41 +35,45 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
*/
|
||||
public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemplateOptions {
|
||||
|
||||
private String password;
|
||||
private String group;
|
||||
private String row;
|
||||
|
||||
public TerremarkInstantiateVAppTemplateOptions withPassword(String password) {
|
||||
this.password = password;
|
||||
productProperty("password", password);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerremarkInstantiateVAppTemplateOptions inGroup(String group) {
|
||||
this.group = group;
|
||||
productProperty("group", group);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerremarkInstantiateVAppTemplateOptions inRow(String row) {
|
||||
this.row = row;
|
||||
productProperty("row", row);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#cpuCount(int)
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#processorCount(int)
|
||||
*/
|
||||
public static TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) {
|
||||
public static TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
return options.cpuCount(cpuCount);
|
||||
return options.processorCount(cpuCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#megabytes(int)
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#memory(long)
|
||||
*/
|
||||
public static TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) {
|
||||
public static TerremarkInstantiateVAppTemplateOptions memory(long megabytes) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
return options.megabytes(megabytes);
|
||||
return options.memory(megabytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#disk(long)
|
||||
*/
|
||||
public static TerremarkInstantiateVAppTemplateOptions disk(long kilobytes) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
return options.disk(kilobytes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,11 +108,28 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp
|
|||
return options.inRow(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#productProperty(String, String)
|
||||
*/
|
||||
public static TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
return (TerremarkInstantiateVAppTemplateOptions) options.productProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TerremarkInstantiateVAppTemplateOptions#productProperties(Map<String, String>)
|
||||
*/
|
||||
public static TerremarkInstantiateVAppTemplateOptions productProperties(
|
||||
Map<String, String> properties) {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
return (TerremarkInstantiateVAppTemplateOptions) options.productProperties(properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.cpuCount(cpuCount);
|
||||
public TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.processorCount(cpuCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,19 +138,22 @@ public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemp
|
|||
}
|
||||
|
||||
@Override
|
||||
public TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.megabytes(megabytes);
|
||||
public TerremarkInstantiateVAppTemplateOptions memory(long megabytes) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.memory(megabytes);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
@Override
|
||||
public TerremarkInstantiateVAppTemplateOptions disk(long kilobytes) {
|
||||
throw new IllegalArgumentException("changing the boot disk size is unsupported in terremark");
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
@Override
|
||||
public TerremarkInstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.productProperties(properties);
|
||||
}
|
||||
|
||||
public String getRow() {
|
||||
return row;
|
||||
@Override
|
||||
public TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) {
|
||||
return (TerremarkInstantiateVAppTemplateOptions) super.productProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
package org.jclouds.vcloud.terremark.xml;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputeOptionHandler extends HandlerWithResult<ComputeOption> {
|
||||
public class ComputeOptionHandler extends HandlerWithResult<ComputeOptions> {
|
||||
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
|
@ -43,8 +43,8 @@ public class ComputeOptionHandler extends HandlerWithResult<ComputeOption> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ComputeOption getResult() {
|
||||
return new ComputeOption(processorCount, memory, costPerHour);
|
||||
public ComputeOptions getResult() {
|
||||
return new ComputeOptions(processorCount, memory, costPerHour);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
|
|
|
@ -30,7 +30,7 @@ import javax.inject.Inject;
|
|||
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -39,12 +39,12 @@ import com.google.common.collect.Sets;
|
|||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputeOptionsHandler extends HandlerWithResult<SortedSet<ComputeOption>> {
|
||||
public class ComputeOptionsHandler extends HandlerWithResult<SortedSet<ComputeOptions>> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final ComputeOptionHandler handler;
|
||||
SortedSet<ComputeOption> result = Sets.newTreeSet();
|
||||
SortedSet<ComputeOptions> result = Sets.newTreeSet();
|
||||
|
||||
@Inject
|
||||
public ComputeOptionsHandler(ComputeOptionHandler handler) {
|
||||
|
@ -52,7 +52,7 @@ public class ComputeOptionsHandler extends HandlerWithResult<SortedSet<ComputeOp
|
|||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<ComputeOption> getResult() {
|
||||
public SortedSet<ComputeOptions> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<InstantiateVAppTemplateParams name="{name}"
|
||||
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<VAppTemplate href="{template}" />
|
||||
<InstantiationParams>
|
||||
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="password" ovf:value="{password}" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="row" ovf:value="{row}" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="group" ovf:value="{group}" />
|
||||
</ProductSection>
|
||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">{count}</VirtualQuantity>
|
||||
</Item>
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">{megabytes}</VirtualQuantity>
|
||||
</Item>
|
||||
</VirtualHardwareSection>
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig>
|
||||
<NetworkAssociation href="{network}" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
|
@ -57,20 +57,22 @@ public class InternetServiceLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetAllInternetServices() throws Exception {
|
||||
SortedSet<InternetService> set = tmClient.getAllInternetServices();
|
||||
SortedSet<InternetService> set = tmClient.getAllInternetServicesInVDC(tmClient
|
||||
.getDefaultVDC().getId());
|
||||
print(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddInternetService() throws InterruptedException {
|
||||
InternetService is = tmClient.addInternetService("test-" + 22, Protocol.TCP, 22);
|
||||
InternetService is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(),
|
||||
"test-" + 22, Protocol.TCP, 22);
|
||||
services.add(is);
|
||||
PublicIpAddress ip = is.getPublicIpAddress();
|
||||
// current bug in terremark
|
||||
// for (int port : new int[] { 80, 8080 }) {
|
||||
// services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port,
|
||||
// Protocol.HTTP, port));
|
||||
// }
|
||||
// for (int port : new int[] { 80, 8080 }) {
|
||||
// services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port,
|
||||
// Protocol.HTTP, port));
|
||||
// }
|
||||
print(tmClient.getInternetServicesOnPublicIp(ip.getId()));
|
||||
}
|
||||
|
||||
|
@ -86,7 +88,8 @@ public class InternetServiceLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetAllPublicIps() throws Exception {
|
||||
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC()) {
|
||||
for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC(tmClient.getDefaultVDC()
|
||||
.getId())) {
|
||||
SortedSet<InternetService> set = tmClient.getInternetServicesOnPublicIp(ip.getId());
|
||||
print(set);
|
||||
}
|
||||
|
|
|
@ -23,14 +23,8 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -38,6 +32,7 @@ import java.lang.reflect.Array;
|
|||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
@ -63,6 +58,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.xml.ComputeOptionsHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||
|
@ -77,7 +73,6 @@ import com.google.inject.AbstractModule;
|
|||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkVCloudAsyncClient}
|
||||
|
@ -102,19 +97,35 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getVDC", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", 3 + "", "1");
|
||||
"1", "name", 3 + "");
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
"Content-Length: 1649\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-test.xml")));
|
||||
|
||||
|
@ -127,18 +138,19 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
public void testInstantiateVAppTemplateOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC",
|
||||
String.class, String.class, String.class, Array.newInstance(
|
||||
InstantiateVAppTemplateOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", 3 + "", "1", cpuCount(4).megabytes(1024).inNetwork(
|
||||
URI.create("http://newnet")));
|
||||
"1", "name", 3 + "", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(
|
||||
1).memory(512).inRow("row").inGroup("group").withPassword("password")
|
||||
.inNetwork(URI.create("http://network")));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpMethod,
|
||||
"Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
"Content-Length: 1912\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
|
||||
|
||||
|
@ -151,13 +163,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
public void testAddInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
||||
String.class, Protocol.class, int.class, Array.newInstance(
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
|
||||
String.class, String.class, Protocol.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", Protocol.TCP, 22);
|
||||
"1", "name", Protocol.TCP, 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
@ -171,13 +183,13 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
|
||||
String.class, Protocol.class, int.class, Array.newInstance(
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToVDC",
|
||||
String.class, String.class, Protocol.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"name", Protocol.TCP, 22, disabled().withDescription("yahoo"));
|
||||
"1", "name", Protocol.TCP, 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
|
@ -190,10 +202,12 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
|
||||
public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServices");
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method);
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServicesInVDC",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
"1");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vdc/internetServices HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/vdc/1/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
|
@ -366,8 +380,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetComputeOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getComputeOptions", String.class);
|
||||
public void testGetComputeOptionsOfVApp() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getComputeOptionsOfVApp",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
|
@ -382,9 +398,9 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetCustomizationOptions() throws SecurityException, NoSuchMethodException,
|
||||
public void testGetCustomizationOptionsOfVApp() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getCustomizationOptions",
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getCustomizationOptionsOfVApp",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
@ -401,6 +417,43 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetComputeOptionsOfCatalogItem() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod("getComputeOptionsOfCatalogItem",
|
||||
String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalogItem/12/options/compute HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ComputeOptionsHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetCustomizationOptionsOfCatalogItem() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudAsyncClient.class.getMethod(
|
||||
"getCustomizationOptionsOfCatalogItem", String.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
|
||||
12);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET http://vcloud/catalogItem/12/options/customization HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertPayloadEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
|
@ -418,21 +471,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP))
|
||||
.toProvider(Providers.<String> of("group"));
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW))
|
||||
.toProvider(Providers.<String> of("row"));
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||
.toProvider(Providers.<String> of("password"));
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
|
||||
.toProvider(Providers.<String> of("1"));
|
||||
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY))
|
||||
.toProvider(Providers.<String> of("512"));
|
||||
bind(String.class)
|
||||
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||
.toProvider(
|
||||
Providers
|
||||
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||
Properties props = new Properties();
|
||||
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
|
||||
"https://vcloud.safesecureweb.com/network/1990");
|
||||
Jsr330.bindProperties(binder(), new TerremarkVCloudPropertiesBuilder(props).build());
|
||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.toInstance("http://catalogItem");
|
||||
|
@ -456,15 +498,6 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
|
|||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
|
@ -31,6 +32,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -44,16 +46,22 @@ import org.jclouds.ssh.SshClient.Factory;
|
|||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.VCloudClientLiveTest;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.Catalog;
|
||||
import org.jclouds.vcloud.domain.CatalogItem;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.ResourceType;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.predicates.TaskSuccess;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.Protocol;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -85,8 +93,24 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testGetAllInternetServices() throws Exception {
|
||||
for (InternetService service : tmClient.getAllInternetServices()) {
|
||||
System.out.println(tmClient.getNodes(service.getId()));
|
||||
for (InternetService service : tmClient.getAllInternetServicesInVDC(tmClient.getDefaultVDC()
|
||||
.getId())) {
|
||||
assertNotNull(tmClient.getNodes(service.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigCustomizationOptions() throws Exception {
|
||||
Catalog response = connection.getCatalog();
|
||||
for (NamedResource resource : response.values()) {
|
||||
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||
CatalogItem item = connection.getCatalogItem(resource.getId());
|
||||
SortedSet<ComputeOptions> options = tmClient
|
||||
.getComputeOptionsOfCatalogItem(item.getId());
|
||||
assert options.size() == 32 || options.size() == 20 : item.getId() + ": "
|
||||
+ options.size();
|
||||
assert tmClient.getCustomizationOptionsOfCatalogItem(item.getId()) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,20 +128,39 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, IOException {
|
||||
String serverName = "adriantest";
|
||||
int processorCount = 1;
|
||||
int memory = 512;
|
||||
// long hardDisk = 4194304;
|
||||
// String catalogOs = "Ubuntu JeOS 9.04 (32-bit)";
|
||||
// String expectedOs = "Ubuntu Linux (32-bit)";
|
||||
long hardDisk = 4194304 / 4 * 10;
|
||||
String catalogOs = "CentOS 5.3 (32-bit)";
|
||||
String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
|
||||
long hardDisk = 4194304;
|
||||
|
||||
String templateId = tmClient.getCatalog().get(catalogOs).getId();
|
||||
String expectedOs = "Ubuntu Linux (32-bit)";
|
||||
// long hardDisk = 4194304 / 4 * 10;
|
||||
// String catalogOs = "CentOS 5.3 (32-bit)";
|
||||
// String expectedOs = "Red Hat Enterprise Linux 5 (32-bit)";
|
||||
|
||||
// lookup the id of the datacenter you are deploying into
|
||||
String vDCId = tmClient.getDefaultVDC().getId();
|
||||
|
||||
System.out.printf("%d: instantiating vApp%n", System.currentTimeMillis());
|
||||
vApp = tmClient.instantiateVAppTemplate(serverName, templateId, vDCId);
|
||||
// lookup the id of the item in the catalog you wish to deploy by name
|
||||
String itemId = tmClient.getCatalog().get("Ubuntu JeOS 9.04 (32-bit)").getId();
|
||||
|
||||
// determine the cheapest configuration size
|
||||
SortedSet<ComputeOptions> sizeOptions = tmClient.getComputeOptionsOfCatalogItem(itemId);
|
||||
ComputeOptions cheapestOption = sizeOptions.first();
|
||||
|
||||
// create an options object to collect the configuration we want.
|
||||
TerremarkInstantiateVAppTemplateOptions instantiateOptions = processorCount(
|
||||
cheapestOption.getProcessorCount()).memory(cheapestOption.getMemory());
|
||||
|
||||
// if this template supports setting the root password, let's add it to our options
|
||||
CustomizationParameters customizationOptions = tmClient
|
||||
.getCustomizationOptionsOfCatalogItem(itemId);
|
||||
if (customizationOptions.canCustomizePassword())
|
||||
instantiateOptions.withPassword("robotsarefun");
|
||||
|
||||
// the vAppTemplateId tends to be the same as the itemId, but just in case, convert
|
||||
String vAppTemplateId = tmClient.getCatalogItem(itemId).getEntity().getId();
|
||||
|
||||
// instantiate, noting vApp returned has minimal details
|
||||
vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, serverName, vAppTemplateId,
|
||||
instantiateOptions);
|
||||
|
||||
assertEquals(vApp.getStatus(), VAppStatus.UNRESOLVED);
|
||||
|
||||
|
@ -147,6 +190,8 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
NamedResource vAppResource = tmClient.getDefaultVDC().getResourceEntities().get(serverName);
|
||||
assertEquals(vAppResource.getId(), vApp.getId());
|
||||
|
||||
int processorCount = cheapestOption.getProcessorCount();
|
||||
long memory = cheapestOption.getMemory();
|
||||
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.OFF);
|
||||
|
||||
|
@ -155,14 +200,15 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
|
||||
vApp = tmClient.getVApp(vApp.getId());
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
System.out.println(tmClient.getComputeOptions(vApp.getId()));
|
||||
System.out.println(tmClient.getCustomizationOptions(vApp.getId()));
|
||||
System.out.println(tmClient.getComputeOptionsOfVApp(vApp.getId()));
|
||||
System.out.println(tmClient.getCustomizationOptionsOfVApp(vApp.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddInternetService() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, IOException {
|
||||
is = tmClient.addInternetService("SSH", Protocol.TCP, 22);
|
||||
is = tmClient.addInternetServiceToVDC(tmClient.getDefaultVDC().getId(), "SSH", Protocol.TCP,
|
||||
22);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
|
||||
|
@ -208,7 +254,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
}
|
||||
|
||||
private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
|
||||
int processorCount, int memory, long hardDisk) {
|
||||
int processorCount, long memory, long hardDisk) {
|
||||
assertEquals(vApp.getName(), serverName);
|
||||
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
|
||||
|
|
|
@ -23,27 +23,23 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
|
||||
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
|
||||
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
@ -53,12 +49,9 @@ import com.google.common.collect.Multimaps;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code
|
||||
* TerremarkBindInstantiateVAppTemplateParamsToXmlPayload}
|
||||
* Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlPayload}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -68,82 +61,31 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP)).toProvider(
|
||||
Providers.<String> of("group"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)).toProvider(
|
||||
Providers.<String> of("row"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD))
|
||||
.toProvider(Providers.<String> of("password"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)).toProvider(
|
||||
Providers.<String> of("1"));
|
||||
bind(String.class).annotatedWith(
|
||||
Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
|
||||
Providers.<String> of("512"));
|
||||
bind(String.class)
|
||||
.annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK))
|
||||
.toProvider(
|
||||
Providers
|
||||
.<String> of("https://vcloud.safesecureweb.com/network/1990"));
|
||||
Properties props = new Properties();
|
||||
props
|
||||
.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
|
||||
"https://vcloud.safesecureweb.com/network/1990");
|
||||
Jsr330.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props)
|
||||
.build(), "properties"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
});
|
||||
|
||||
public void testApplyInputStream() throws IOException {
|
||||
public void testAllOptions() throws IOException {
|
||||
|
||||
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||
Multimap<String, String> headers = Multimaps
|
||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||
"/terremark/InstantiateVAppTemplateParams-options-test.xml"));
|
||||
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
|
||||
.<String, String> create());
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getEndpoint()).andReturn(
|
||||
URI.create("http://localhost/key")).anyTimes();
|
||||
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(
|
||||
"application/unknown").atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expected);
|
||||
replay(request);
|
||||
|
||||
TerremarkBindInstantiateVAppTemplateParamsToXmlPayload binder = injector
|
||||
.getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class);
|
||||
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "name");
|
||||
map.put("password", "password");
|
||||
map.put("row", "row");
|
||||
map.put("group", "group");
|
||||
map.put("template", "http://catalogItem/3");
|
||||
map.put("count", "1");
|
||||
map.put("megabytes", "512");
|
||||
map.put("network", "http://network");
|
||||
binder.bindToRequest(request, map);
|
||||
}
|
||||
|
||||
public void testApplyInputStream2() throws IOException {
|
||||
|
||||
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams-test-2.xml"));
|
||||
Multimap<String, String> headers = Multimaps
|
||||
.synchronizedMultimap(HashMultimap.<String, String> create());
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getEndpoint()).andReturn(
|
||||
URI.create("http://localhost/key")).anyTimes();
|
||||
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(
|
||||
"application/unknown").atLeastOnce();
|
||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||
expect(request.getArgs()).andReturn(
|
||||
new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(1)
|
||||
.memory(512).inRow("row").inGroup("group").withPassword(
|
||||
"password").inNetwork(URI.create("http://network")) })
|
||||
.atLeastOnce();
|
||||
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown")
|
||||
.atLeastOnce();
|
||||
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
|
||||
request.setPayload(expected);
|
||||
replay(request);
|
||||
|
@ -154,9 +96,7 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "name");
|
||||
map.put("template", "http://catalogItem/3");
|
||||
map.put("count", "1");
|
||||
map.put("megabytes", "512");
|
||||
map.put("network", "http://network");
|
||||
binder.bindToRequest(request, map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.testng.annotations.AfterTest;
|
|||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -77,11 +78,9 @@ public class TerremarkVCloudComputeClientLiveTest {
|
|||
}
|
||||
|
||||
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
|
||||
.put(Image.CENTOS_53,
|
||||
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
|
||||
Image.RHEL_53,
|
||||
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
|
||||
Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
|
||||
.put(Image.CENTOS_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)"))
|
||||
.put(Image.RHEL_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)"))
|
||||
.put(Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
|
||||
Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
|
||||
|
||||
private Predicate<InetAddress> addressTester;
|
||||
|
@ -94,8 +93,9 @@ public class TerremarkVCloudComputeClientLiveTest {
|
|||
String serverName = getCompatibleServerName(toTest);
|
||||
int processorCount = 1;
|
||||
int memory = 512;
|
||||
Map<String, String> properties = ImmutableMap.of();
|
||||
|
||||
id = client.start(serverName, processorCount, memory, toTest);
|
||||
id = client.start(serverName, toTest, processorCount, memory, properties);
|
||||
Expectation expectation = expectationMap.get(toTest);
|
||||
|
||||
TerremarkVApp vApp = tmClient.getVApp(id);
|
||||
|
@ -105,7 +105,8 @@ public class TerremarkVCloudComputeClientLiveTest {
|
|||
}
|
||||
|
||||
private String getCompatibleServerName(Image toTest) {
|
||||
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
|
||||
String serverName = CaseFormat.UPPER_UNDERSCORE
|
||||
.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0,
|
||||
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
|
||||
return serverName;
|
||||
}
|
||||
|
|
|
@ -66,10 +66,6 @@ public class TerremarkVCloudRestClientModuleTest {
|
|||
|
||||
@Test
|
||||
void postStrings() throws IOException {
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils
|
||||
.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml")));
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("CreateInternetService"))), Utils
|
||||
.toStringAndClose(getClass().getResourceAsStream(
|
||||
|
|
|
@ -23,11 +23,13 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
|
||||
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
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.megabytes;
|
||||
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.withPassword;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
|
@ -53,39 +55,39 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
|||
public void testInGroup() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
options.inGroup("group1");
|
||||
assertEquals(options.getGroup(), "group1");
|
||||
assertEquals(options.getProperties().get("group"), "group1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInGroupStatic() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = inGroup("group1");
|
||||
assertEquals(options.getGroup(), "group1");
|
||||
assertEquals(options.getProperties().get("group"), "group1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInRow() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
options.inRow("row1");
|
||||
assertEquals(options.getRow(), "row1");
|
||||
assertEquals(options.getProperties().get("row"), "row1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInRowStatic() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = inRow("row1");
|
||||
assertEquals(options.getRow(), "row1");
|
||||
assertEquals(options.getProperties().get("row"), "row1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPassword() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
options.withPassword("password1");
|
||||
assertEquals(options.getPassword(), "password1");
|
||||
assertEquals(options.getProperties().get("password"), "password1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPasswordStatic() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = withPassword("password1");
|
||||
assertEquals(options.getPassword(), "password1");
|
||||
assertEquals(options.getProperties().get("password"), "password1");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -103,30 +105,42 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
|
|||
|
||||
@Test
|
||||
public void testCpuCount() {
|
||||
assertEquals(cpuCount(3).getCpuCount(), "3");
|
||||
assertEquals(processorCount(3).getCpuCount(), "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCpuCountStatic() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = cpuCount(3);
|
||||
TerremarkInstantiateVAppTemplateOptions options = processorCount(3);
|
||||
assertEquals(options.getCpuCount(), "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMegabytes() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
options.megabytes(512);
|
||||
assertEquals(options.getMegabytes(), "512");
|
||||
options.memory(512);
|
||||
assertEquals(options.getMemorySizeMegabytes(), "512");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMegabytesStatic() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = megabytes(512);
|
||||
assertEquals(options.getMegabytes(), "512");
|
||||
TerremarkInstantiateVAppTemplateOptions options = memory(512);
|
||||
assertEquals(options.getMemorySizeMegabytes(), "512");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testMegabytesStaticWrong() {
|
||||
megabytes(511);
|
||||
memory(511);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testDiskSizeKilobytes() {
|
||||
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
|
||||
options.disk(512);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
public void testDiskSizeKilobytesStatic() {
|
||||
disk(512);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.io.InputStream;
|
|||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -43,8 +43,8 @@ public class ComputeOptionHandlerTest extends BaseHandlerTest {
|
|||
public void test1() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/ComputeOption.xml");
|
||||
|
||||
ComputeOption result = (ComputeOption) factory.create(
|
||||
ComputeOptions result = (ComputeOptions) factory.create(
|
||||
injector.getInstance(ComputeOptionHandler.class)).parse(is);
|
||||
assertEquals(result, new ComputeOption(1, 512, 0.039f));
|
||||
assertEquals(result, new ComputeOptions(1, 512, 0.039f));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.net.UnknownHostException;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOption;
|
||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
|
@ -46,9 +46,9 @@ public class ComputeOptionsHandlerTest extends BaseHandlerTest {
|
|||
public void test1() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/ComputeOptions.xml");
|
||||
|
||||
SortedSet<ComputeOption> result = factory.create(
|
||||
SortedSet<ComputeOptions> result = factory.create(
|
||||
injector.getInstance(ComputeOptionsHandler.class)).parse(is);
|
||||
assertEquals(result, ImmutableSortedSet.of(new ComputeOption(1, 512, 0.039f),
|
||||
new ComputeOption(8, 16384, 1.61f)));
|
||||
assertEquals(result, ImmutableSortedSet.of(new ComputeOptions(1, 512, 0.039f),
|
||||
new ComputeOptions(8, 16384, 1.61f)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,38 +1 @@
|
|||
<InstantiateVAppTemplateParams name="name"
|
||||
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<VAppTemplate href="http://catalogItem/3" />
|
||||
<InstantiationParams>
|
||||
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="password" ovf:value="password" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="row" ovf:value="row" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="group" ovf:value="group" />
|
||||
</ProductSection>
|
||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</VirtualQuantity>
|
||||
</Item>
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1024</VirtualQuantity>
|
||||
</Item>
|
||||
</VirtualHardwareSection>
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig>
|
||||
<NetworkAssociation href="http://newnet" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
||||
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="name" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="http://catalogItem/3"/><InstantiationParams><ProductSection xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:q1="http://www.vmware.com/vcloud/v1"><Property xmlns="http://schemas.dmtf.org/ovf/envelope/1" ovf:key="group" ovf:value="group"/><Property xmlns="http://schemas.dmtf.org/ovf/envelope/1" ovf:key="password" ovf:value="password"/><Property xmlns="http://schemas.dmtf.org/ovf/envelope/1" ovf:key="row" ovf:value="row"/></ProductSection><VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1"><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity></Item></VirtualHardwareSection><NetworkConfigSection><NetworkConfig name="name"><Features><FenceMode>allowInOut</FenceMode><Dhcp>false</Dhcp></Features><NetworkAssociation href="http://network"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
|
|
@ -1,38 +0,0 @@
|
|||
<InstantiateVAppTemplateParams name="name"
|
||||
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<VAppTemplate href="http://catalogItem/3" />
|
||||
<InstantiationParams>
|
||||
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="password" ovf:value="password" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="row" ovf:value="row" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="group" ovf:value="group" />
|
||||
</ProductSection>
|
||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity>
|
||||
</Item>
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity>
|
||||
</Item>
|
||||
</VirtualHardwareSection>
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig>
|
||||
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
|
@ -1,38 +1 @@
|
|||
<InstantiateVAppTemplateParams name="name"
|
||||
xml:lang="en" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<VAppTemplate href="http://catalogItem/3" />
|
||||
<InstantiationParams>
|
||||
<ProductSection xmlns:q1="http://www.vmware.com/vcloud/v1"
|
||||
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="password" ovf:value="password" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="row" ovf:value="row" />
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1"
|
||||
ovf:key="group" ovf:value="group" />
|
||||
</ProductSection>
|
||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1">
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity>
|
||||
</Item>
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID>
|
||||
<ResourceType
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>
|
||||
<VirtualQuantity
|
||||
xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity>
|
||||
</Item>
|
||||
</VirtualHardwareSection>
|
||||
<NetworkConfigSection>
|
||||
<NetworkConfig>
|
||||
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
|
||||
</NetworkConfig>
|
||||
</NetworkConfigSection>
|
||||
</InstantiationParams>
|
||||
</InstantiateVAppTemplateParams>
|
||||
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="name" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VAppTemplate href="http://catalogItem/3"/><InstantiationParams><ProductSection xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:q1="http://www.vmware.com/vcloud/v1"/><VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v1"><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</VirtualQuantity></Item><Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512</VirtualQuantity></Item></VirtualHardwareSection><NetworkConfigSection><NetworkConfig name="name"><Features><FenceMode>allowInOut</FenceMode><Dhcp>false</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>
|
Loading…
Reference in New Issue