Issue 280: instantiateVapp 1.0 now works, but has a hard-coded internal vapp network

This commit is contained in:
Adrian Cole 2010-08-26 01:48:11 -07:00
parent f98af108bb
commit 025b8aa12d
39 changed files with 462 additions and 286 deletions

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.bluelock;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.util.Properties;
@ -35,6 +36,7 @@ public class BlueLockVCloudDirectorPropertiesBuilder extends VCloudPropertiesBui
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://vcenterprise.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "internet01");
return properties;
}

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.bluelock;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.util.Properties;
@ -35,6 +36,7 @@ public class BlueLockVCloudExpressPropertiesBuilder extends VCloudExpressPropert
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://express.bluelock.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_NETWORK, "Internal In and Out");
return properties;
}

View File

@ -23,16 +23,14 @@ import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.net.URI;
import java.util.Map;
import javax.inject.Named;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.config.VCloudExpressRestClientModule;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@ -46,20 +44,6 @@ import com.google.common.collect.Iterables;
@ConfiguresRestClient
public class BlueLockVCloudExpressRestClientModule extends VCloudExpressRestClientModule {
@Override
protected URI provideDefaultNetwork(CommonVCloudClient client) {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
Map<String, ReferenceType> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return Iterables.getOnlyElement(Iterables.filter(networks.values(), new Predicate<ReferenceType>() {
@Override
public boolean apply(ReferenceType input) {
return input.getName().equals("Internal In and Out");
}
})).getHref();
}
@Override
protected URI provideCatalog(Org org, @Named(PROPERTY_IDENTITY) final String user) {

View File

@ -48,7 +48,7 @@ import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
@ -117,8 +117,7 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
// TODO convert this.
@MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,

View File

@ -42,7 +42,7 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "1.0");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0");
properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1");
properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty("jclouds.dns_name_length_min", "1");

View File

@ -0,0 +1,168 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.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_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.annotation.Resource;
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.logging.Logger;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
@Resource
protected Logger logger = Logger.NULL;
protected final String ns;
protected final String schema;
protected final BindToStringPayload stringBinder;
protected final URI defaultNetwork;
protected final FenceMode defaultFenceMode;
@Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Network URI network, @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultNetwork = network;
this.defaultFenceMode = FenceMode.fromValue(fenceMode);
}
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
String template = checkNotNull(postParams.remove("template"), "template");
String network = defaultNetwork.toASCIIString();
FenceMode fenceMode = defaultFenceMode;
logger.warn("hack alert; we need to actually get the network name from the vAppTemplate's ovf:Network ovf:name");
String networkName = "vAppNet-vApp Internal";
boolean deploy = true;
boolean powerOn = true;
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) {
network = ifNullDefaultTo(options.getNetwork(), network);
fenceMode = ifNullDefaultTo(options.getFenceMode(), defaultFenceMode);
networkName = ifNullDefaultTo(options.getNetworkName(), networkName);
deploy = ifNullDefaultTo(options.shouldDeploy(), deploy);
powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn);
}
try {
stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkName, fenceMode, URI
.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
throw new RuntimeException(e);
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
protected String generateXml(String name, boolean deploy, boolean powerOn, String template, String networkName,
FenceMode fenceMode, URI network) throws ParserConfigurationException, FactoryConfigurationError,
TransformerException {
XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, network);
rootBuilder.e("Source").a("href", template);
rootBuilder.e("AllEULAsAccepted").t("true");
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, FenceMode fenceMode, URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");
networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks");
XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", name).e(
"Configuration");
configurationBuilder.e("ParentNetwork").a("href", network.toASCIIString());
if (fenceMode != null) {
configurationBuilder.e("FenceMode").t(fenceMode.toString());
}
}
protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
return XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
}
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
return (InstantiateVAppTemplateOptions) arg;
} else if (arg instanceof InstantiateVAppTemplateOptions[]) {
InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg;
return (options.length > 0) ? options[0] : null;
}
}
return null;
}
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
}
protected <T> T ifNullDefaultTo(T value, T defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -24,7 +24,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
@ -46,6 +45,7 @@ import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.ImmutableMap;
@ -73,13 +73,13 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
@Inject
public BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
this.ns = ns;
this.apiVersion = apiVersion;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultNetwork = URI.create(network);
this.defaultNetwork = network;
this.defaultFenceMode = fenceMode;
}
@ -95,7 +95,6 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
Map<String, String> properties = Maps.newTreeMap();
String network = defaultNetwork.toASCIIString();
String fenceMode = defaultFenceMode;
String networkName = name;
@ -106,11 +105,10 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
fenceMode = "allowInOut";
networkName = ifNullDefaultTo(options.getNetworkName(), networkName);
addQuantity(options, virtualHardwareQuantity);
properties.putAll(options.getProperties());
}
try {
stringBinder.bindToRequest(request, generateXml(name, template, properties, virtualHardwareQuantity,
networkName, fenceMode, URI.create(network)));
stringBinder.bindToRequest(request, generateXml(name, template, virtualHardwareQuantity, networkName,
fenceMode, URI.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -121,15 +119,14 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
}
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName, @Nullable String fenceMode,
URI network) throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
protected String generateXml(String name, String template, SortedMap<ResourceType, String> virtualHardwareQuantity,
String networkName, @Nullable String fenceMode, URI 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, networkName, fenceMode, network);
Properties outputProperties = new Properties();
@ -137,17 +134,6 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload implemen
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", ns).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, @Nullable String fenceMode,
URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e("NetworkConfig").a(

View File

@ -37,7 +37,6 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
@ -72,24 +71,18 @@ public class VCloudComputeClientImpl extends CommonVCloudComputeClientImpl<VAppT
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VAppTemplate template = VCloudClient.class.cast(client).getVAppTemplate(templateId);
VApp vAppResponse = VCloudClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getHref(),
template.getHref(), name, options);
VApp vAppResponse = VCloudClient.class.cast(client).instantiateVAppTemplateInVDC(VDC, templateId, name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = VCloudClient.class.cast(client).deployAndPowerOnVAppOrVm(vAppResponse.getHref());
if (options.shouldBlockOnDeploy()) {
Task task = vAppResponse.getTasks().get(0);
if (options.shouldBlock()) {
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse
.getName(), task));
}
logger.debug("<< deployed and powered on vApp(%s)", vAppResponse.getName());
logger.debug("<< ready vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
return parseAndValidateResponse(null, vAppResponse);
}
@Override

View File

@ -35,7 +35,6 @@ import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
@ -66,30 +65,30 @@ public class VCloudExpressComputeClientImpl extends
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
VDC vdc = client.getVDC(VDC);
VCloudExpressVAppTemplate template = VCloudExpressClient.class.cast(client).getVAppTemplate(templateId);
VCloudExpressVApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(vdc.getHref(),
template.getHref(), name, options);
VCloudExpressVApp vAppResponse = VCloudExpressClient.class.cast(client).instantiateVAppTemplateInVDC(VDC,
templateId, name, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
if (options.shouldDeploy()) {
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
logger.debug(">> deploying vApp(%s)", vAppResponse.getName());
Task task = VCloudExpressClient.class.cast(client).deployVApp(vAppResponse.getHref());
if (options.shouldBlockOnDeploy()) {
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
Task task = VCloudExpressClient.class.cast(client).deployVApp(vAppResponse.getHref());
if (options.shouldBlock()) {
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy", vAppResponse.getName(), task));
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
if (options.shouldPowerOn()) {
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = VCloudExpressClient.class.cast(client).powerOnVApp(vAppResponse.getHref());
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(),
task));
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
}
logger.debug("<< deployed vApp(%s)", vAppResponse.getName());
logger.debug(">> powering vApp(%s)", vAppResponse.getName());
task = VCloudExpressClient.class.cast(client).powerOnVApp(vAppResponse.getHref());
if (!taskTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "powerOn", vAppResponse.getName(), task));
}
logger.debug("<< on vApp(%s)", vAppResponse.getName());
}
return parseAndValidateResponse(template, vAppResponse);
return parseAndValidateResponse(VCloudExpressClient.class.cast(client).getVAppTemplate(templateId), vAppResponse);
}
@Override

View File

@ -64,7 +64,7 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue())
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
if (!template.getOptions().shouldBlockUntilRunning())
options.blockOnDeploy(false);
options.block(false);
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
.getImage().getId()), name, options, template.getOptions().getInboundPorts());
VApp vApp = client.getVApp(URI.create(metaMap.get("id")));

View File

@ -65,7 +65,7 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue())
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
if (!template.getOptions().shouldBlockUntilRunning())
options.blockOnDeploy(false);
options.block(false);
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template
.getImage().getId()), name, options, template.getOptions().getInboundPorts());
VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id")));

View File

@ -66,8 +66,8 @@ import org.jclouds.vcloud.CommonVCloudClient;
import org.jclouds.vcloud.VCloudToken;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudSession;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Network;
@ -83,9 +83,13 @@ import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import domain.VCloudVersionsAsyncClient;
@ -123,16 +127,16 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
}).to(new TypeLiteral<AllCatalogItemsInCatalog>() {
});
}
@Singleton
@Provides
CommonVCloudAsyncClient provideCommonVCloudAsyncClient(A in){
CommonVCloudAsyncClient provideCommonVCloudAsyncClient(A in) {
return in;
}
@Singleton
@Provides
CommonVCloudClient provideCommonVCloudClient(S in){
CommonVCloudClient provideCommonVCloudClient(S in) {
return in;
}
@ -381,24 +385,29 @@ public class CommonVCloudRestClientModule<S extends CommonVCloudClient, A extend
return getLast(getLast(catalogs.get().values()).keySet());
}
@Provides
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK)
@Singleton
String provideDefaultNetworkString(@Network URI network) {
return network.toASCIIString();
}
@Provides
@Network
@Singleton
protected URI provideDefaultNetwork(CommonVCloudClient client) {
protected URI provideDefaultNetwork(@org.jclouds.vcloud.endpoints.VDC URI defaultVDC, CommonVCloudClient client,
Injector injector) {
if (authException.get() != null)
throw authException.get();
try {
org.jclouds.vcloud.domain.VDC vDC = client.findVDCInOrgNamed(null, null);
org.jclouds.vcloud.domain.VDC vDC = client.getVDC(defaultVDC);
Map<String, ReferenceType> networks = vDC.getAvailableNetworks();
checkState(networks.size() > 0, "No networks present in vDC: " + vDC.getName());
return get(networks.values(), 0).getHref();
if (networks.size() == 1)
return Iterables.getLast(networks.values()).getHref();
try {
String networkName = injector.getInstance(Key.get(String.class, Names
.named(PROPERTY_VCLOUD_DEFAULT_NETWORK)));
ReferenceType network = networks.get(networkName);
checkState(network != null, String.format("network named %s not in %s", networkName, networks.keySet()));
return network.getHref();
} catch (ConfigurationException e) {
throw new IllegalStateException(String.format("you must specify the property %s as one of %s",
PROPERTY_VCLOUD_DEFAULT_NETWORK, networks.keySet()), e);
}
} catch (AuthorizationException e) {
authException.set(e);
throw e;

View File

@ -23,12 +23,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 org.jclouds.vcloud.domain.network.FenceMode;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
@ -42,25 +39,43 @@ public class InstantiateVAppTemplateOptions {
private String network;
private FenceMode fenceMode;
private String networkName;
private boolean blockOnDeploy = true;
private Map<String, String> properties = Maps.newTreeMap();
private boolean block = true;
private boolean deploy = true;
private boolean powerOn = true;
public boolean shouldBlockOnDeploy() {
return blockOnDeploy;
public boolean shouldBlock() {
return block;
}
public InstantiateVAppTemplateOptions blockOnDeploy(boolean blockOnDeploy) {
this.blockOnDeploy = blockOnDeploy;
public boolean shouldDeploy() {
return deploy;
}
public boolean shouldPowerOn() {
return powerOn;
}
/**
* deploy the vapp after it is instantiated?
*/
public InstantiateVAppTemplateOptions deploy(boolean deploy) {
this.deploy = deploy;
return this;
}
public InstantiateVAppTemplateOptions productProperty(String key, String value) {
properties.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
/**
* powerOn the vapp after it is instantiated?
*/
public InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
this.powerOn = powerOn;
return this;
}
public InstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
this.properties.putAll(checkNotNull(properties, "properties"));
/**
* block until instantiate or deployment operations complete?
*/
public InstantiateVAppTemplateOptions block(boolean block) {
this.block = block;
return this;
}
@ -70,6 +85,9 @@ public class InstantiateVAppTemplateOptions {
return this;
}
/**
* The name of the vApp internal network that you want to connect to a VDC network
*/
public InstantiateVAppTemplateOptions networkName(String networkName) {
this.networkName = checkNotNull(networkName, "networkName");
return this;
@ -92,7 +110,7 @@ public class InstantiateVAppTemplateOptions {
return this;
}
public InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
public InstantiateVAppTemplateOptions network(URI networkLocation) {
this.network = checkNotNull(networkLocation, "networkLocation").toASCIIString();
return this;
}
@ -121,18 +139,30 @@ public class InstantiateVAppTemplateOptions {
return fenceMode;
}
public Map<String, String> getProperties() {
return properties;
}
public static class Builder {
/**
* @see InstantiateVAppTemplateOptions#blockOnDeploy
* @see InstantiateVAppTemplateOptions#block
*/
public static InstantiateVAppTemplateOptions blockOnDeploy(boolean blockOnDeploy) {
public static InstantiateVAppTemplateOptions block(boolean block) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.blockOnDeploy(blockOnDeploy);
return options.block(block);
}
/**
* @see InstantiateVAppTemplateOptions#deploy
*/
public static InstantiateVAppTemplateOptions deploy(boolean deploy) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.deploy(deploy);
}
/**
* @see InstantiateVAppTemplateOptions#powerOn
*/
public static InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.powerOn(powerOn);
}
/**
@ -160,11 +190,11 @@ public class InstantiateVAppTemplateOptions {
}
/**
* @see InstantiateVAppTemplateOptions#inNetwork(URI)
* @see InstantiateVAppTemplateOptions#network(URI)
*/
public static InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.inNetwork(networkLocation);
return options.network(networkLocation);
}
/**
@ -183,28 +213,13 @@ public class InstantiateVAppTemplateOptions {
return options.networkName(networkName);
}
/**
* @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);
}
}
@Override
public String toString() {
return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes
+ ", diskSizeKilobytes=" + diskSizeKilobytes + ", network=" + network + ", networkName=" + networkName
+ ", fenceMode=" + fenceMode + ", properties=" + properties + "]";
+ ", fenceMode=" + fenceMode + "]";
}
@Override
@ -217,7 +232,6 @@ public class InstantiateVAppTemplateOptions {
result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode());
result = prime * result + ((network == null) ? 0 : network.hashCode());
result = prime * result + ((networkName == null) ? 0 : networkName.hashCode());
result = prime * result + ((properties == null) ? 0 : properties.hashCode());
return result;
}
@ -260,11 +274,6 @@ public class InstantiateVAppTemplateOptions {
return false;
} else if (!networkName.equals(other.networkName))
return false;
if (properties == null) {
if (other.properties != null)
return false;
} else if (!properties.equals(other.properties))
return false;
return true;
}

View File

@ -28,7 +28,7 @@ public interface VCloudConstants {
public static final String PROPERTY_VCLOUD_VERSION_SCHEMA = "jclouds.vcloud.version.schema";
/**
* automatically renew vcloud token before this interval expires.
* name of the default network, in the default VDC that your vApp will join.
*/
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";

View File

@ -22,6 +22,7 @@ package org.jclouds.vcloud;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.networkName;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals;
@ -58,6 +59,7 @@ import org.jclouds.vcloud.domain.internal.CatalogItemImpl;
import org.jclouds.vcloud.domain.internal.OrgImpl;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -78,6 +80,7 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -102,7 +105,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp.xml")),
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -116,17 +119,18 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor
.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp",
processorCount(1).memory(512).disk(1024).inNetwork(
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990")));
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", networkName("aloha")
.fenceMode(FenceMode.NAT_ROUTED).network(
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991")));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-cpumemdisk.xml")),
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
@ -142,7 +146,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512)
.disk(1024).inNetwork(URI.create("https://vcenterprise.bluelock.com/network/1990")));
.disk(1024).network(URI.create("https://vcenterprise.bluelock.com/network/1990")));
}
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
@ -455,7 +459,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\"/>",
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -472,7 +476,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\" powerOn=\"true\"/>",
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -539,7 +543,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\"/>",
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -559,7 +563,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request,
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\" saveState=\"true\"/>",
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -768,7 +772,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
}
@Override
protected URI provideDefaultNetwork(CommonVCloudClient client) {
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
}

View File

@ -77,6 +77,7 @@ import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -119,7 +120,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"), "my-vapp", processorCount(1)
.memory(512).disk(1024).fenceMode(FenceMode.BRIDGED).inNetwork(
.memory(512).disk(1024).fenceMode(FenceMode.BRIDGED).network(
URI.create("https://vcloud.safesecureweb.com/network/1990")));
assertRequestLineEquals(request,
@ -143,7 +144,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
String.class, InstantiateVAppTemplateOptions[].class);
processor.createRequest(method, URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), "CentOS 01", processorCount(1).memory(512)
.disk(1024).inNetwork(URI.create("https://vcloud.safesecureweb.com/network/1990")));
.disk(1024).network(URI.create("https://vcloud.safesecureweb.com/network/1990")));
}
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
@ -683,7 +684,7 @@ public class VCloudExpressAsyncClientTest extends RestClientTest<VCloudExpressAs
}
@Override
protected URI provideDefaultNetwork(CommonVCloudClient client) {
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}

View File

@ -57,7 +57,7 @@ public class BindDeployVAppParamsToXmlPayloadTest {
});
public void testPowerOnTrue() throws IOException {
String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\" powerOn=\"true\"/>";
String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>";
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
@ -73,7 +73,7 @@ public class BindDeployVAppParamsToXmlPayloadTest {
}
public void testDefault() throws IOException {
String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\"/>";
String expected = "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>";
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();

View File

@ -24,17 +24,19 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
@ -42,6 +44,7 @@ import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.name.Names;
/**
@ -56,21 +59,28 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcenterprise.bluelock.com/api/v1.0/network/1990");
Names.bindProperties(binder(), checkNotNull(new VCloudPropertiesBuilder(props).build(), "properties"));
}
@SuppressWarnings("unused")
@Network
@Provides
@Singleton
URI provideNetwork() {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1990");
}
});
public void testDefault() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp.xml"));
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
@ -80,48 +90,51 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
}
// TODO!!! figure out how to get this to work
@Test(enabled = false)
public void testWithProcessorMemoryDisk() throws IOException {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.processorCount(1).memory(512).disk(1024);
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-cpumemdisk.xml"));
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
map.put("network", "https://vcenterprise.bluelock.com/api/v1.0/network/1990");
binder.bindToRequest(request, map);
verify(request);
}
public void testWithNetworkNameDhcpFenceMode() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/newvapp-networknamedhcpfencemode.xml"));
public void testWithNetworkNameFenceMode() throws IOException {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.networkName("aloha").fenceMode(FenceMode.NAT_ROUTED).network(
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"));
String expected = Utils.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
map.put("network", "https://vcenterprise.bluelock.com/api/v1.0/network/1990");
map.put("networkName", "aloha");
map.put("fenceMode", FenceMode.BRIDGED.toString());
binder.bindToRequest(request, map);
verify(request);

View File

@ -24,17 +24,19 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudExpressPropertiesBuilder;
import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
@ -42,6 +44,7 @@ import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.name.Names;
/**
@ -56,9 +59,16 @@ public class BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK, "https://vcloud.safesecureweb.com/network/1990");
Names.bindProperties(binder(), checkNotNull(new VCloudExpressPropertiesBuilder(props).build(), "properties"));
}
@SuppressWarnings("unused")
@Network
@Provides
@Singleton
URI provideNetwork() {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
});
public void testDefault() throws IOException {

View File

@ -57,7 +57,7 @@ public class BindUndeployVAppParamsToXmlPayloadTest {
});
public void testSaveStateTrue() throws IOException {
String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\" saveState=\"true\"/>";
String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>";
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
@ -73,7 +73,7 @@ public class BindUndeployVAppParamsToXmlPayloadTest {
}
public void testDefault() throws IOException {
String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.0\"/>";
String expected = "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>";
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();

View File

@ -94,8 +94,7 @@ public class VCloudComputeClientLiveTest {
int memory = 512;
VAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName);
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties(
ImmutableMap.of("foo", "bar"));
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024);
id = URI.create(computeClient.start(null, template.getHref(), templateName, options).get("id"));
Expectation expectation = expectationMap.get(toTest);

View File

@ -35,8 +35,8 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
@ -94,8 +94,7 @@ public class VCloudExpressComputeClientLiveTest {
int memory = 512;
VCloudExpressVAppTemplate template = client.findVAppTemplateInOrgCatalogNamed(null, null, templateName);
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024).productProperties(
ImmutableMap.of("foo", "bar"));
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024);
id = URI.create(computeClient.start(null, template.getHref(), templateName, options).get("id"));
Expectation expectation = expectationMap.get(toTest);
@ -117,8 +116,8 @@ public class VCloudExpressComputeClientLiveTest {
assert !addressTester.apply(publicAddress);
}
private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs, int processorCount,
int memory, long hardDisk) {
private void verifyConfigurationOfVApp(VCloudExpressVApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) {
// assertEquals(vApp.getName(), serverName);
// assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(Iterables

View File

@ -49,7 +49,7 @@ public class InstantiateVAppTemplateOptionsTest {
@Test
public void testInNetwork() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.inNetwork(URI.create("http://localhost"));
options.network(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}

View File

@ -1 +1 @@
<CloneVAppParams xmlns="http://www.vmware.com/vcloud/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="false" name="my-vapp" powerOn="false" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.0 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VApp href="https://vcenterprise.bluelock.com/api/v1.0/vapp/4181" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>
<CloneVAppParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="false" name="my-vapp" powerOn="false" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><VApp href="https://vcenterprise.bluelock.com/api/v1.0/vapp/4181" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>

View File

@ -1 +1 @@
<CloneVAppParams xmlns="http://www.vmware.com/vcloud/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="true" name="new-linux-server" powerOn="true" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.0 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vApp</Description><VApp href="https://vcenterprise.bluelock.com/api/v1.0/vapp/201" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>
<CloneVAppParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" deploy="true" name="new-linux-server" powerOn="true" xsi:schemaLocation="http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd"><Description>The description of the new vApp</Description><VApp href="https://vcenterprise.bluelock.com/api/v1.0/vapp/201" type="application/vnd.vmware.vcloud.vApp+xml"/></CloneVAppParams>

View File

@ -0,0 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" deploy="true" name="my-vapp" powerOn="true"><InstantiationParams><NetworkConfigSection><ovf:Info>Configuration parameters for logical networks</ovf:Info><NetworkConfig networkName="aloha"><Configuration><ParentNetwork href="https://vcenterprise.bluelock.com/api/v1.0/network/1991"/><FenceMode>natRouted</FenceMode></Configuration></NetworkConfig></NetworkConfigSection></InstantiationParams><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"/><AllEULAsAccepted>true</AllEULAsAccepted></InstantiateVAppTemplateParams>

View File

@ -0,0 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" deploy="true" name="my-vapp" powerOn="true"><InstantiationParams><NetworkConfigSection><ovf:Info>Configuration parameters for logical networks</ovf:Info><NetworkConfig networkName="vAppNet-vApp Internal"><Configuration><ParentNetwork href="https://vcenterprise.bluelock.com/api/v1.0/network/1990"/><FenceMode>bridged</FenceMode></Configuration></NetworkConfig></NetworkConfigSection></InstantiationParams><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"/><AllEULAsAccepted>true</AllEULAsAccepted></InstantiateVAppTemplateParams>

View File

@ -21,25 +21,25 @@ package org.jclouds.vcloud.terremark.binders;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
import java.util.Map.Entry;
import javax.annotation.Nullable;
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.BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.jamesmurty.utils.XMLBuilder;
@ -55,26 +55,34 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
@Inject
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_API_VERSION) String apiVersion, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) {
super(stringBinder, apiVersion, ns, schema, network, fenceMode);
}
ThreadLocal<Map<String, String>> propLocal = new ThreadLocal<Map<String, String>>();
@Override
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName, @Nullable String fenceMode,
URI network) throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
return super.generateXml(name, template, properties, virtualHardwareQuantity, networkName, fenceMode, network);
protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
InstantiateVAppTemplateOptions options = super.findOptionsInArgsOrNull(gRequest);
if (options != null && options instanceof TerremarkInstantiateVAppTemplateOptions)
propLocal.set(TerremarkInstantiateVAppTemplateOptions.class.cast(options).getProperties());
return options;
}
@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", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1");
} else {
super.addPropertiesifPresent(instantiationParamsBuilder, properties);
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,
SortedMap<ResourceType, String> virtualHardwareQuantity) {
XMLBuilder productSectionBuilder = instantiationParamsBuilder.e("ProductSection").a("xmlns:q1", ns).a(
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
if (propLocal.get() != null) {
for (Entry<String, String> entry : propLocal.get().entrySet()) {
productSectionBuilder.e("Property").a("xmlns", "http://schemas.dmtf.org/ovf/envelope/1").a("ovf:key",
entry.getKey()).a("ovf:value", entry.getValue());
}
propLocal.set(null);
}
super.addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
}
}

View File

@ -52,6 +52,7 @@ 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.PublicIpAddress;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
@ -95,13 +96,14 @@ public class TerremarkVCloudComputeClient extends VCloudExpressComputeClientImpl
logger.warn("trmk does not support resizing the primary disk; unsetting disk size");
}
// we only get IP addresses after "deploy"
if (portsToOpen.length > 0 && !options.shouldBlockOnDeploy())
if (portsToOpen.length > 0 && !options.shouldBlock())
throw new IllegalArgumentException("We cannot open ports on terremark unless we can deploy the vapp");
String password = null;
VCloudExpressVAppTemplate template = client.getVAppTemplate(templateId);
if (template.getDescription().indexOf("Windows") != -1) {
if (template.getDescription().indexOf("Windows") != -1
&& options instanceof TerremarkInstantiateVAppTemplateOptions) {
password = passwordGenerator.get();
options.getProperties().put("password", password);
TerremarkInstantiateVAppTemplateOptions.class.cast(options).getProperties().put("password", password);
}
Map<String, String> response = super.start(VDC, templateId, name, options, portsToOpen);
if (password != null) {

View File

@ -40,7 +40,7 @@ public class TemplateToInstantiateOptions implements Function<Template, Terremar
TerremarkInstantiateVAppTemplateOptions options = processorCount(
Double.valueOf(from.getSize().getCores()).intValue()).memory(from.getSize().getRam());
if (!from.getOptions().shouldBlockUntilRunning())
options.blockOnDeploy(false);
options.block(false);
String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint();
if (sshKeyFingerprint != null)
options.sshKeyFingerprint(sshKeyFingerprint);

View File

@ -24,16 +24,18 @@ import java.util.Map;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.internal.util.Maps;
/**
*
* @author Adrian Cole
*
*/
public class TerremarkInstantiateVAppTemplateOptions extends
InstantiateVAppTemplateOptions {
public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemplateOptions {
public TerremarkInstantiateVAppTemplateOptions sshKeyFingerprint(
String sshKeyFingerprint) {
private final Map<String, String> properties = Maps.newLinkedHashMap();
public TerremarkInstantiateVAppTemplateOptions sshKeyFingerprint(String sshKeyFingerprint) {
productProperty("sshKeyFingerprint", sshKeyFingerprint);
return this;
}
@ -43,8 +45,7 @@ public class TerremarkInstantiateVAppTemplateOptions extends
return this;
}
public TerremarkInstantiateVAppTemplateOptions secondaryDNS(
String secondaryDNS) {
public TerremarkInstantiateVAppTemplateOptions secondaryDNS(String secondaryDNS) {
productProperty("secondaryDNS", secondaryDNS);
return this;
}
@ -69,8 +70,7 @@ public class TerremarkInstantiateVAppTemplateOptions extends
/**
* @see TerremarkInstantiateVAppTemplateOptions#processorCount(int)
*/
public static TerremarkInstantiateVAppTemplateOptions processorCount(
int cpuCount) {
public static TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.processorCount(cpuCount);
}
@ -78,8 +78,7 @@ public class TerremarkInstantiateVAppTemplateOptions extends
/**
* @see TerremarkInstantiateVAppTemplateOptions#memory(long)
*/
public static TerremarkInstantiateVAppTemplateOptions memory(
long megabytes) {
public static TerremarkInstantiateVAppTemplateOptions memory(long megabytes) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.memory(megabytes);
}
@ -93,19 +92,17 @@ public class TerremarkInstantiateVAppTemplateOptions extends
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#inNetwork(URI)
* @see TerremarkInstantiateVAppTemplateOptions#network(URI)
*/
public static TerremarkInstantiateVAppTemplateOptions inNetwork(
URI networkLocation) {
public static TerremarkInstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.inNetwork(networkLocation);
return options.network(networkLocation);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#withPassword(String)
*/
public static TerremarkInstantiateVAppTemplateOptions withPassword(
String password) {
public static TerremarkInstantiateVAppTemplateOptions withPassword(String password) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.withPassword(password);
}
@ -129,8 +126,7 @@ public class TerremarkInstantiateVAppTemplateOptions extends
/**
* @see TerremarkInstantiateVAppTemplateOptions#sshKeyFingerprint(String)
*/
public static TerremarkInstantiateVAppTemplateOptions sshKeyFingerprint(
String sshKeyFingerprint) {
public static TerremarkInstantiateVAppTemplateOptions sshKeyFingerprint(String sshKeyFingerprint) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.sshKeyFingerprint(sshKeyFingerprint);
}
@ -138,8 +134,7 @@ public class TerremarkInstantiateVAppTemplateOptions extends
/**
* @see TerremarkInstantiateVAppTemplateOptions#primaryDNS(String)
*/
public static TerremarkInstantiateVAppTemplateOptions primaryDNS(
String primaryDNS) {
public static TerremarkInstantiateVAppTemplateOptions primaryDNS(String primaryDNS) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.primaryDNS(primaryDNS);
}
@ -147,47 +142,37 @@ public class TerremarkInstantiateVAppTemplateOptions extends
/**
* @see TerremarkInstantiateVAppTemplateOptions#secondaryDNS(String)
*/
public static TerremarkInstantiateVAppTemplateOptions secondaryDNS(
String secondaryDNS) {
public static TerremarkInstantiateVAppTemplateOptions secondaryDNS(String secondaryDNS) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.secondaryDNS(secondaryDNS);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#productProperty(String,
* String)
* @see TerremarkInstantiateVAppTemplateOptions#productProperty(String, String)
*/
public static TerremarkInstantiateVAppTemplateOptions productProperty(
String key, String value) {
public static TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return (TerremarkInstantiateVAppTemplateOptions) options
.productProperty(key, value);
return (TerremarkInstantiateVAppTemplateOptions) options.productProperty(key, value);
}
/**
* @see
* TerremarkInstantiateVAppTemplateOptions#productProperties(Map<String
* , String>)
* @see TerremarkInstantiateVAppTemplateOptions#productProperties(Map<String , String>)
*/
public static TerremarkInstantiateVAppTemplateOptions productProperties(
Map<String, String> properties) {
public static TerremarkInstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return (TerremarkInstantiateVAppTemplateOptions) options
.productProperties(properties);
return (TerremarkInstantiateVAppTemplateOptions) options.productProperties(properties);
}
}
@Override
public TerremarkInstantiateVAppTemplateOptions processorCount(int cpuCount) {
return (TerremarkInstantiateVAppTemplateOptions) super
.processorCount(cpuCount);
return (TerremarkInstantiateVAppTemplateOptions) super.processorCount(cpuCount);
}
@Override
public TerremarkInstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
return (TerremarkInstantiateVAppTemplateOptions) super
.inNetwork(networkLocation);
public TerremarkInstantiateVAppTemplateOptions network(URI networkLocation) {
return (TerremarkInstantiateVAppTemplateOptions) super.network(networkLocation);
}
@Override
@ -197,21 +182,20 @@ public class TerremarkInstantiateVAppTemplateOptions extends
@Override
public TerremarkInstantiateVAppTemplateOptions disk(long kilobytes) {
throw new IllegalArgumentException(
"changing the boot disk size is unsupported in terremark");
throw new IllegalArgumentException("changing the boot disk size is unsupported in terremark");
}
@Override
public TerremarkInstantiateVAppTemplateOptions productProperties(
Map<String, String> properties) {
return (TerremarkInstantiateVAppTemplateOptions) super
.productProperties(properties);
public TerremarkInstantiateVAppTemplateOptions productProperties(Map<String, String> properties) {
this.properties.putAll(properties);
return this;
}
@Override
public TerremarkInstantiateVAppTemplateOptions productProperty(String key,
String value) {
return (TerremarkInstantiateVAppTemplateOptions) super.productProperty(
key, value);
public TerremarkInstantiateVAppTemplateOptions productProperty(String key, String value) {
this.properties.put(key, value);
return this;
}
public Map<String, String> getProperties() {
return properties;
}
}

View File

@ -72,6 +72,7 @@ import org.jclouds.vcloud.xml.VCloudExpressVAppHandler;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -144,8 +145,8 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row")
.inGroup("group").withPassword("password").inNetwork(URI.create("http://network")));
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").network(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -472,7 +473,7 @@ public class TerremarkECloudAsyncClientTest extends RestClientTest<TerremarkEClo
}
@Override
protected URI provideDefaultNetwork(CommonVCloudClient client) {
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}

View File

@ -88,6 +88,7 @@ import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
@ -193,8 +194,8 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
URI.class, String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"), URI.create("https://vcloud/vAppTemplate/3"),
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inRow("row")
.inGroup("group").withPassword("password").inNetwork(URI.create("http://network")));
"name", TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup("group")
.withPassword("password").inRow("row").network(URI.create("http://network")));
assertRequestLineEquals(request,
"POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
@ -736,7 +737,7 @@ public class TerremarkVCloudExpressAsyncClientTest extends RestClientTest<Terrem
}
@Override
protected URI provideDefaultNetwork(CommonVCloudClient client) {
protected URI provideDefaultNetwork(URI vdc, CommonVCloudClient client, Injector injector) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}

View File

@ -20,20 +20,20 @@
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_DEFAULT_NETWORK;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import javax.inject.Singleton;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.inject.name.Names;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.testng.annotations.Test;
@ -45,6 +45,8 @@ 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.name.Names;
/**
* Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlPayload}
@ -58,30 +60,32 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayloadTest {
@Override
protected void configure() {
Properties props = new Properties();
props
.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
"https://vcloud.safesecureweb.com/network/1990");
Names.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props)
.build(), "properties"));
Names
.bindProperties(binder(), checkNotNull(new TerremarkVCloudPropertiesBuilder(props).build(),
"properties"));
}
@SuppressWarnings("unused")
@Network
@Provides
@Singleton
URI provideNetwork() {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
});
public void testAllOptions() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-options-test.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.getArgs()).andReturn(
new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2)
.memory(512).inRow("row").inGroup("group").withPassword(
"password").inNetwork(URI.create("http://network")) })
.atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn("application/unknown")
new Object[] { TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2).memory(512).inGroup(
"group").withPassword("password").inRow("row").network(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);

View File

@ -65,13 +65,10 @@ public class TerremarkVCloudComputeClientTest {
TerremarkVCloudExpressClient client = createMock(TerremarkVCloudExpressClient.class);
VCloudExpressVApp vApp = createMock(VCloudExpressVApp.class);
expect(client.getVDC(vdcURI)).andReturn(vdc);
expect(client.getVAppTemplate(templateURI)).andReturn(template);
// TODO make this call only once
expect(client.getVAppTemplate(templateURI)).andReturn(template);
expect(client.getVAppTemplate(templateURI)).andReturn(template);
expect(vdc.getHref()).andReturn(vdcURI);
expect(template.getHref()).andReturn(templateURI);
expect(
client.instantiateVAppTemplateInVDC(vdcURI, templateURI, "name",
new TerremarkInstantiateVAppTemplateOptions().productProperty("password", "password")))

View File

@ -89,7 +89,7 @@ public class TerremarkInstantiateVAppTemplateOptionsTest {
@Test
public void testInNetwork() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.inNetwork(URI.create("http://localhost"));
options.network(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}