Merge branch 'master' of git@github.com:jclouds/jclouds

This commit is contained in:
Ivan Meredith 2010-04-18 20:30:43 +12:00
commit 597a3d97c2
17 changed files with 261 additions and 57 deletions

View File

@ -617,7 +617,22 @@ pageTracker._trackPageview();
</plugin>
</plugins>
</build>
</profile>
</profile>
<profile>
<id>clojure-1.2</id>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.2.0-master-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure-contrib</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
<reporting>
<plugins>

View File

@ -19,6 +19,8 @@
package org.jclouds.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
@ -31,6 +33,7 @@ import java.net.URI;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.vcloud.domain.FenceMode;
/**
* Builds properties used in VCloud Clients
@ -44,7 +47,10 @@ public class VCloudPropertiesBuilder extends PropertiesBuilder {
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 8 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
"http://vcloud.safesecureweb.com/ns/vcloud.xsd");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false");
properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString());
return properties;
}

View File

@ -22,12 +22,15 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DISK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
@ -67,7 +70,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final Map<ResourceType, String> virtualHardwareToInstanceId = ImmutableMap.of(
ResourceType.PROCESSOR, "1", ResourceType.MEMORY, "2", ResourceType.DISK_DRIVE, "9");
private final String defaultNetwork;
private final URI defaultNetwork;
private final FenceMode defaultFenceMode;
private final boolean defaultDhcpEnabled;
/**
* To allow for optional injection, since guice doesn't allow unresolved constants in
@ -89,13 +94,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
public BindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Named(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED) String defaultDhcpEnabled,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String defaultFenceMode,
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
OptionalConstantsHolder defaultsHolder) {
this.ns = ns;
this.schema = schema;
this.stringBinder = stringBinder;
this.defaultVirtualHardwareQuantity = Maps.newHashMap();
this.defaultNetwork = network;
this.defaultNetwork = URI.create(network);
this.defaultFenceMode = FenceMode.fromValue(defaultFenceMode);
this.defaultDhcpEnabled = Boolean.parseBoolean(defaultDhcpEnabled);
if (defaultsHolder.cpuCount != null)
this.defaultVirtualHardwareQuantity.put(ResourceType.PROCESSOR, defaultsHolder.cpuCount);
if (defaultsHolder.memorySizeMegabytes != null)
@ -115,6 +124,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
String name = checkNotNull(postParams.remove("name"), "name");
String template = checkNotNull(postParams.remove("template"), "template");
String network = postParams.remove("network");
String fenceMode = postParams.remove("fenceMode");
String dhcpEnabled = postParams.remove("dhcpEnabled");
String networkName = postParams.remove("networkName");
SortedMap<ResourceType, String> virtualHardwareQuantity = extractVirtualQuantityFromPostParams(postParams);
@ -126,10 +138,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
network = networkFromOptions != null ? networkFromOptions : network;
properties.putAll(options.getProperties());
}
network = network == null ? defaultNetwork : network;
try {
stringBinder.bindToRequest(request, generateXml(name, template, properties,
virtualHardwareQuantity, network));
virtualHardwareQuantity, networkName == null ? name : networkName,
fenceMode == null ? defaultFenceMode : FenceMode.fromValue(fenceMode),
dhcpEnabled == null ? defaultDhcpEnabled : Boolean.parseBoolean(dhcpEnabled),
network == null ? defaultNetwork : URI.create(network)));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (FactoryConfigurationError e) {
@ -151,8 +165,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String network)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName,
FenceMode fenceMode, boolean dhcp, URI network) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name);
rootBuilder.e("VAppTemplate").a("href", template);
@ -160,7 +175,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addPropertiesifPresent(instantiationParamsBuilder, properties);
addVirtualQuantityIfPresent(instantiationParamsBuilder, virtualHardwareQuantity);
addNetworkConfig(instantiationParamsBuilder, name, network);
addNetworkConfig(instantiationParamsBuilder, networkName, fenceMode, dhcp, network);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
@ -180,13 +195,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name,
String network) {
FenceMode fenceMode, boolean dhcp, URI network) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e(
"NetworkConfig").a("name", name);
XMLBuilder featuresBuilder = networkConfigBuilder.e("Features");
featuresBuilder.e("FenceMode").t(FenceMode.ALLOW_IN_OUT.value());
featuresBuilder.e("Dhcp").t("false");
networkConfigBuilder.e("NetworkAssociation").a("href", network);
featuresBuilder.e("FenceMode").t(fenceMode.value());
featuresBuilder.e("Dhcp").t(dhcp + "");
networkConfigBuilder.e("NetworkAssociation").a("href", network.toASCIIString());
}
protected void addVirtualQuantityIfPresent(XMLBuilder instantiationParamsBuilder,

View File

@ -18,8 +18,8 @@
*/
package org.jclouds.vcloud.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.InetAddress;
import java.util.Map;
@ -69,16 +69,14 @@ public class BaseVCloudComputeClient implements VCloudComputeClient {
this.vAppStatusToNodeState = vAppStatusToNodeState;
}
public Map<String, String> start(String vDCId, String name, String templateId, int minCores,
int minMegs, Long diskSize, Map<String, String> properties, int... portsToOpen) {
logger
.debug(
">> instantiating vApp vDC(%s) name(%s) template(%s) minCores(%d) minMegs(%d) diskSize(%d) properties(%s) ",
vDCId, name, templateId, minCores, minMegs, diskSize, properties);
InstantiateVAppTemplateOptions options = processorCount(minCores).memory(minMegs)
.productProperties(properties);
if (diskSize != null)
options.disk(diskSize);
@Override
public Map<String, String> start(String vDCId, String name, String templateId,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
checkNotNull(options, "options");
logger.debug(">> instantiating vApp vDC(%s) name(%s) template(%s) options(%s) ", vDCId, name,
templateId, options);
VApp vAppResponse = client.instantiateVAppTemplateInVDC(vDCId, name, templateId, options);
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());

View File

@ -22,7 +22,7 @@ import java.net.InetAddress;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.inject.ImplementedBy;
@ -50,10 +50,8 @@ public interface VCloudComputeClient {
* amount of virtual cpu cores
* @param megs
* amount of ram in megabytes
* @param diskSizeKilobytes
* size of disk in kilobytes, null is ok
* @param properties
* sets product properties on the vApp
* @param options
* options for instantiating the vApp; null is ok
* @param portsToOpen
* opens the following ports on the public ip address
* @return map contains at least the following properties
@ -62,8 +60,8 @@ public interface VCloudComputeClient {
* login password</li>
* </ol>
*/
Map<String, String> start(String vDCId, String name, String templateId, int cores, int megs,
@Nullable Long diskSizeKilobytes, Map<String, String> properties, int... portsToOpen);
Map<String, String> start(String vDCId, String name, String templateId,
InstantiateVAppTemplateOptions options, int... portsToOpen);
/**
* returns a set of addresses that are only visible to the private network.

View File

@ -21,9 +21,12 @@ package org.jclouds.vcloud.compute.config;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.InetAddress;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
@ -84,6 +87,7 @@ import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
@ -189,11 +193,15 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
@Override
public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount(
Double.valueOf(template.getSize().getCores()).intValue()).memory(
template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
options.networkName("templateId=" + template.getImage().getId());
Map<String, String> metaMap = computeClient.start(template.getLocation().getId(), name,
template.getImage().getId(), Double.valueOf(template.getSize().getCores())
.intValue(), template.getSize().getRam(),
template.getSize().getDisk() * 1024 * 1024l, ImmutableMap.<String, String> of(),
template.getOptions().getInboundPorts());
template.getImage().getId(), options, template.getOptions().getInboundPorts());
VApp vApp = client.getVApp(metaMap.get("id"));
return newCreateNodeResponse(tag, template, metaMap, vApp);
}
@ -306,10 +314,13 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
extra.put("processor/count", Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)).getVirtualQuantity()
+ "");
for (ResourceAllocation disk : vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)) {
extra.put(String.format("disk_drive/%s/kb", disk.getId()), disk.getVirtualQuantity() + "");
}
for (Entry<String, InetAddress> net : vApp.getNetworkToAddresses().entries()) {
extra.put(String.format("network/%s/ip", net.getKey()), net.getValue().getHostAddress());
}
return extra;
}

View File

@ -24,6 +24,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.vcloud.domain.FenceMode;
import com.google.common.collect.Maps;
/**
@ -38,6 +40,9 @@ public class InstantiateVAppTemplateOptions {
private String diskSizeKilobytes;
private String network;
private Map<String, String> properties = Maps.newTreeMap();
private String fenceMode;
private String dhcpEnabled;
private String networkName;
public InstantiateVAppTemplateOptions productProperty(String key, String value) {
properties.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
@ -55,6 +60,21 @@ public class InstantiateVAppTemplateOptions {
return this;
}
public InstantiateVAppTemplateOptions networkName(String networkName) {
this.networkName = checkNotNull(networkName, "networkName");
return this;
}
public InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) {
this.fenceMode = checkNotNull(fenceMode, "fenceMode").toString();
return this;
}
public InstantiateVAppTemplateOptions dhcpEnabled(boolean dhcpEnabled) {
this.dhcpEnabled = dhcpEnabled + "";
return this;
}
public InstantiateVAppTemplateOptions memory(long megabytes) {
checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512");
this.memorySizeMegabytes = megabytes + "";
@ -88,6 +108,18 @@ public class InstantiateVAppTemplateOptions {
return network;
}
public String getNetworkName() {
return networkName;
}
public String getFenceMode() {
return fenceMode;
}
public String getDhcpEnabled() {
return dhcpEnabled;
}
public Map<String, String> getProperties() {
return properties;
}
@ -126,6 +158,30 @@ public class InstantiateVAppTemplateOptions {
return options.inNetwork(networkLocation);
}
/**
* @see InstantiateVAppTemplateOptions#fenceMode(FenceMode)
*/
public static InstantiateVAppTemplateOptions fenceMode(FenceMode fenceMode) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.fenceMode(fenceMode);
}
/**
* @see InstantiateVAppTemplateOptions#dhcpEnabled(boolean)
*/
public static InstantiateVAppTemplateOptions dhcpEnabled(boolean dhcpEnabled) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.dhcpEnabled(dhcpEnabled);
}
/**
* @see InstantiateVAppTemplateOptions#networkName(String)
*/
public static InstantiateVAppTemplateOptions networkName(String networkName) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.networkName(networkName);
}
/**
* @see InstantiateVAppTemplateOptions#productProperty(String,String)
*/
@ -143,4 +199,12 @@ public class InstantiateVAppTemplateOptions {
}
}
@Override
public String toString() {
return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes="
+ memorySizeMegabytes + ", diskSizeKilobytes=" + diskSizeKilobytes + ", network="
+ network + ", networkName=" + networkName + ", fenceMode=" + fenceMode
+ ", dhcpEnabled=" + dhcpEnabled + ", properties=" + properties + "]";
}
}

View File

@ -39,6 +39,9 @@ public interface VCloudConstants {
/**
* megabytes
*/
public static final String PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED = "jclouds.vcloud.defaults.dhcpenabled";
public static final String PROPERTY_VCLOUD_DEFAULT_FENCEMODE = "jclouds.vcloud.defaults.fencemode";
public static final String PROPERTY_VCLOUD_DEFAULT_MEMORY = "jclouds.vcloud.defaults.memorysizemegabytes";
public static final String PROPERTY_VCLOUD_DEFAULT_NETWORK = "jclouds.vcloud.defaults.network";
/**

View File

@ -19,6 +19,8 @@
package org.jclouds.vcloud;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
@ -43,6 +45,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.TasksList;
@ -517,6 +520,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Override
protected void configure() {
Properties props = new Properties();
props.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false");
props.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString());
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,
"https://vcloud.safesecureweb.com/network/1990");
props.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v0.8");

View File

@ -34,6 +34,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.ResourceType;
import org.testng.annotations.Test;
@ -65,7 +66,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
}
});
public void testDefault() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hosting.xml"));
@ -89,7 +89,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
verify(request);
}
public void testWithProcessorMemoryDisk() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
@ -120,4 +119,33 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
verify(request);
}
public void testWithNetworkNameDhcpFenceMode() throws IOException {
String expected = Utils.toStringAndClose(getClass().getResourceAsStream(
"/newvapp-hostingnetworknamedhcpfencemode.xml"));
Multimap<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(null).atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setPayload(expected);
replay(request);
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
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("network", "https://vcloud.safesecureweb.com/network/1990");
map.put("networkName", "aloha");
map.put("fenceMode", FenceMode.BRIDGED.toString());
map.put("dhcpEnabled", "true");
binder.bindToRequest(request, map);
verify(request);
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
@ -37,6 +38,7 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -86,11 +88,12 @@ public class VCloudComputeClientLiveTest {
String serverName = getCompatibleServerName(toTest);
int processorCount = 1;
int memory = 512;
long disk = 10 * 1025 * 1024;
Map<String, String> properties = ImmutableMap.of("foo", "bar");
id = computeClient.start(client.getDefaultVDC().getId(), serverName, templateId,
processorCount, memory, disk, properties).get("id");
InstantiateVAppTemplateOptions options = processorCount(1).memory(512).disk(10 * 1025 * 1024)
.productProperties(ImmutableMap.of("foo", "bar"));
id = computeClient.start(client.getDefaultVDC().getId(), serverName, templateId, options)
.get("id");
Expectation expectation = expectationMap.get(toTest);
VApp vApp = client.getVApp(id);
@ -136,7 +139,7 @@ public class VCloudComputeClientLiveTest {
if (id != null)
computeClient.stop(id);
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
@ -150,8 +153,7 @@ public class VCloudComputeClientLiveTest {
client = injector.getInstance(VCloudClient.class);
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
}));
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(
OsFamily.CENTOS,
expectationMap = ImmutableMap.<OsFamily, Expectation> builder().put(OsFamily.CENTOS,
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build();
service = "vcloudtest";
templateId = "3";

View File

@ -55,6 +55,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assert allData.getExtra().get("processor/count") != null;
assert allData.getExtra().get("disk_drive/1/kb") != null;
assert allData.getExtra().get("memory/mb") != null;
System.out.println(allData.getExtra());
}
}
}

View File

@ -18,15 +18,19 @@
*/
package org.jclouds.vcloud.options;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.dhcpEnabled;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.fenceMode;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.networkName;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.vcloud.domain.FenceMode;
import org.testng.annotations.Test;
import com.google.inject.Guice;
@ -104,4 +108,43 @@ public class InstantiateVAppTemplateOptionsTest {
disk(0);
}
@Test
public void testNetworkName() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.networkName("network");
assertEquals(options.getNetworkName(), "network");
}
@Test
public void testNetworkNameStatic() {
InstantiateVAppTemplateOptions options = networkName("network");
assertEquals(options.getNetworkName(), "network");
}
@Test
public void testFenceMode() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.fenceMode(FenceMode.BLOCK_IN_OUT);
assertEquals(options.getFenceMode(), "blockInOut");
}
@Test
public void testFenceModeStatic() {
InstantiateVAppTemplateOptions options = fenceMode(FenceMode.BLOCK_IN_OUT);
assertEquals(options.getFenceMode(), "blockInOut");
}
@Test
public void testDhcpEnabled() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.dhcpEnabled(true);
assertEquals(options.getDhcpEnabled(), "true");
}
@Test
public void testDhcpEnabledStatic() {
InstantiateVAppTemplateOptions options = dhcpEnabled(true);
assertEquals(options.getDhcpEnabled(), "true");
}
}

View File

@ -0,0 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="CentOS 01" 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><NetworkConfigSection><NetworkConfig name="aloha"><Features><FenceMode>bridged</FenceMode><Dhcp>true</Dhcp></Features><NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990"/></NetworkConfig></NetworkConfigSection></InstantiationParams></InstantiateVAppTemplateParams>

View File

@ -18,12 +18,14 @@
*/
package org.jclouds.vcloud.terremark.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.net.URI;
import java.util.Map;
import java.util.SortedMap;
@ -36,6 +38,7 @@ import javax.xml.transform.TransformerException;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.domain.ResourceType;
import com.jamesmurty.utils.XMLBuilder;
@ -53,22 +56,25 @@ public class TerremarkBindInstantiateVAppTemplateParamsToXmlPayload extends
public TerremarkBindInstantiateVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
@Named(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED) String defaultDhcpEnabled,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String defaultFenceMode,
@Named(PROPERTY_VCLOUD_DEFAULT_NETWORK) String network,
OptionalConstantsHolder optionalDefaults) {
super(stringBinder, ns, schema, network, optionalDefaults);
super(stringBinder, ns, schema, defaultDhcpEnabled, defaultFenceMode, network,
optionalDefaults);
}
@Override
protected String generateXml(String name, String template, Map<String, String> properties,
SortedMap<ResourceType, String> virtualHardwareQuantity, String network)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
SortedMap<ResourceType, String> virtualHardwareQuantity, String networkName,
FenceMode fenceMode, boolean dhcp, URI network) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
checkNotNull(virtualHardwareQuantity.get(ResourceType.PROCESSOR),
"cpuCount must be present in instantiateVapp on terremark");
checkNotNull(virtualHardwareQuantity.get(ResourceType.MEMORY),
"memorySizeMegabytes must be present in instantiateVapp on terremark");
checkArgument(virtualHardwareQuantity.get(ResourceType.DISK_DRIVE) == null,
"diskSizeKilobytes no settable on instantiateVapp on terremark");
return super.generateXml(name, template, properties, virtualHardwareQuantity, network);
return super.generateXml(name, template, properties, virtualHardwareQuantity, networkName,
fenceMode, dhcp, network);
}
@Override

View File

@ -34,6 +34,7 @@ import org.jclouds.vcloud.compute.BaseVCloudComputeClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
@ -68,10 +69,12 @@ public class TerremarkVCloudComputeClient extends BaseVCloudComputeClient {
}
@Override
public Map<String, String> start(String vDCId, String name, String templateId, int minCores,
int minMegs, Long diskSize, Map<String, String> properties, int... portsToOpen) {
Map<String, String> response = super.start(vDCId, name, templateId, minCores, minMegs, null,
properties, portsToOpen);// trmk does not support resizing the primary disk
public Map<String, String> start(String vDCId, String name, String templateId,
InstantiateVAppTemplateOptions options, int... portsToOpen) {
if (options.getDiskSizeKilobytes() != null) {
logger.warn("trmk does not support resizing the primary disk; unsetting disk size");
}
Map<String, String> response = super.start(vDCId, name, templateId, options, portsToOpen);
if (portsToOpen.length > 0)
createPublicAddressMappedToPorts(response.get("id"), portsToOpen);
return response;

View File

@ -19,6 +19,8 @@
package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_CPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_MEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_NETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
@ -48,6 +50,7 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.domain.FenceMode;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.VCloudApi;
@ -561,6 +564,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
@Override
protected void configure() {
Properties props = new Properties();
props.setProperty(PROPERTY_VCLOUD_DEFAULT_DHCP_ENABLED, "false");
props.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.ALLOW_IN_OUT.toString());
props.setProperty(PROPERTY_VCLOUD_DEFAULT_CPUCOUNT, "1");
props.setProperty(PROPERTY_VCLOUD_DEFAULT_MEMORY, "512");
props.put(PROPERTY_VCLOUD_DEFAULT_NETWORK,