Issue 573:Set vApp description in vcloud driver

This commit is contained in:
Adrian Cole 2011-05-25 16:03:15 -06:00
parent 0914978560
commit bd69558081
12 changed files with 233 additions and 95 deletions

View File

@ -66,8 +66,6 @@ import com.jamesmurty.utils.XMLBuilder;
*/
@Singleton
public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
@Resource
protected Logger logger = Logger.NULL;
protected final String ns;
protected final String schema;
@ -124,7 +122,9 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
networkConfig = ImmutableSet.of(networknetworkConfigDecorator.apply(null));
try {
return stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkConfig,
return stringBinder.bindToRequest(
request,
generateXml(name, options.getDescription(), deploy, powerOn, template, networkConfig,
customizeOnInstantiate));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
@ -200,10 +200,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
}
protected String generateXml(String name, boolean deploy, boolean powerOn, URI template,
Iterable<? extends NetworkConfig> networkConfig, @Nullable Boolean customizeOnInstantiate)
protected String generateXml(String name, @Nullable String description, boolean deploy, boolean powerOn,
URI template, Iterable<? extends NetworkConfig> networkConfig, @Nullable Boolean customizeOnInstantiate)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
if (description != null)
rootBuilder.e("Description").t(description);
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addNetworkConfig(instantiationParamsBuilder, networkConfig);
addCustomizationConfig(instantiationParamsBuilder, customizeOnInstantiate);
@ -217,9 +219,10 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected void addCustomizationConfig(XMLBuilder instantiationParamsBuilder, Boolean customizeOnInstantiate) {
if (customizeOnInstantiate != null) {
// XMLBuilder customizationSectionBuilder = instantiationParamsBuilder.e("CustomizationSection");
// customizationSectionBuilder.e("ovf:Info").t("VApp template customization section");
// customizationSectionBuilder.e("CustomizeOnInstantiate").t(customizeOnInstantiate.toString());
// XMLBuilder customizationSectionBuilder =
// instantiationParamsBuilder.e("CustomizationSection");
// customizationSectionBuilder.e("ovf:Info").t("VApp template customization section");
// customizationSectionBuilder.e("CustomizeOnInstantiate").t(customizeOnInstantiate.toString());
}
}
@ -238,8 +241,8 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
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");
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) {
@ -253,6 +256,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
return null;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");

View File

@ -26,11 +26,11 @@ import org.jclouds.util.Preconditions2;
import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
/**
* Contains options supported in the {@code ComputeService#runNode} operation on the "vcloud"
* provider. <h2>
* Usage</h2> The recommended way to instantiate a VCloudTemplateOptions object is to statically
* import VCloudTemplateOptions.* and invoke a static creation method followed by an instance
* mutator (if needed):
* Contains options supported in the {@code ComputeService#runNode} operation on
* the "vcloud" provider. <h2>
* Usage</h2> The recommended way to instantiate a VCloudTemplateOptions object
* is to statically import VCloudTemplateOptions.* and invoke a static creation
* method followed by an instance mutator (if needed):
* <p/>
* <code>
* import static org.jclouds.compute.options.VCloudTemplateOptions.Builder.*;
@ -57,16 +57,28 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
if (getCustomizationScript() != null)
eTo.customizationScript(getCustomizationScript());
if (getDescription() != null)
eTo.description(getDescription());
if (getIpAddressAllocationMode() != null)
eTo.ipAddressAllocationMode(getIpAddressAllocationMode());
}
}
private String description = null;
private String customizationScript = null;
private IpAddressAllocationMode ipAddressAllocationMode = null;
public static final VCloudTemplateOptions NONE = new VCloudTemplateOptions();
/**
* Optional description. Used for the Description of the vApp created by this
* instantiation.
*/
public VCloudTemplateOptions description(String description) {
this.description = description;
return this;
}
/**
* Specifies the customizationScript used to run instances with
*/
@ -77,7 +89,8 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
}
/**
* Specifies the ipAddressAllocationMode used to for network interfaces on the VMs
* Specifies the ipAddressAllocationMode used to for network interfaces on
* the VMs
*/
public VCloudTemplateOptions ipAddressAllocationMode(IpAddressAllocationMode ipAddressAllocationMode) {
this.ipAddressAllocationMode = ipAddressAllocationMode;
@ -85,6 +98,14 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
}
public static class Builder {
/**
* @see VCloudTemplateOptions#description
*/
public static VCloudTemplateOptions description(String description) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.description(description));
}
/**
* @see VCloudTemplateOptions#customizationScript
*/
@ -152,6 +173,13 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
}
/**
* @return description of the vApp
*/
public String getDescription() {
return description;
}
/**
* @return customizationScript on the vms
*/
@ -178,9 +206,10 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
/**
*
* special thing is that we do assume if you are passing groups that you have everything you need
* already defined. for example, our option inboundPorts normally creates ingress rules
* accordingly but if we notice you've specified securityGroups, we do not mess with rules at all
* special thing is that we do assume if you are passing groups that you have
* everything you need already defined. for example, our option inboundPorts
* normally creates ingress rules accordingly but if we notice you've
* specified securityGroups, we do not mess with rules at all
*
* @see TemplateOptions#inboundPorts
*/
@ -253,6 +282,7 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((customizationScript == null) ? 0 : customizationScript.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((ipAddressAllocationMode == null) ? 0 : ipAddressAllocationMode.hashCode());
return result;
}
@ -271,6 +301,11 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
return false;
} else if (!customizationScript.equals(other.customizationScript))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (ipAddressAllocationMode != other.ipAddressAllocationMode)
return false;
return true;
@ -278,10 +313,11 @@ public class VCloudTemplateOptions extends TemplateOptions implements Cloneable
@Override
public String toString() {
return "[customizationScript=" + (customizationScript != null) + ", ipAddressAllocationMode="
+ ipAddressAllocationMode + ", inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey="
+ (privateKey != null) + ", publicKey=" + (publicKey != null) + ", runScript=" + (script != null)
+ ", port:seconds=" + port + ":" + seconds + ", metadata/details: " + includeMetadata + "]";
return "[customizationScript=" + (customizationScript != null) + ", description=" + description
+ ", ipAddressAllocationMode=" + ipAddressAllocationMode + ", inboundPorts="
+ Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
+ (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds
+ ", metadata/details: " + includeMetadata + "]";
}
}

View File

@ -18,13 +18,14 @@
*/
package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
@ -82,6 +83,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
IpAddressAllocationMode ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions())
.getIpAddressAllocationMode();
options.description(VCloudTemplateOptions.class.cast(template.getOptions()).getDescription());
options.customizeOnInstantiate(false);
options.deploy(false);
options.powerOn(false);

View File

@ -35,11 +35,15 @@ public class InstantiateVAppTemplateOptions {
private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
private Boolean customizeOnInstantiate;
private String description = null;
private boolean block = true;
private boolean deploy = true;
private boolean powerOn = true;
public String getDescription() {
return description;
}
public boolean shouldBlock() {
return block;
}
@ -52,6 +56,15 @@ public class InstantiateVAppTemplateOptions {
return powerOn;
}
/**
* Optional description. Used for the Description of the vApp created by this
* instantiation.
*/
public InstantiateVAppTemplateOptions description(String description) {
this.description = description;
return this;
}
/**
* deploy the vapp after it is instantiated?
*/
@ -124,6 +137,14 @@ public class InstantiateVAppTemplateOptions {
return options.block(block);
}
/**
* @see InstantiateVAppTemplateOptions#description
*/
public static InstantiateVAppTemplateOptions description(String description) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.description(description);
}
/**
* @see InstantiateVAppTemplateOptions#deploy
*/
@ -160,8 +181,8 @@ public class InstantiateVAppTemplateOptions {
@Override
public String toString() {
return "[networkConfig=" + networkConfig + ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy="
+ (deploy) + ", powerOn=" + (powerOn) + "]";
return "[networkConfig=" + networkConfig + ", customizeOnInstantiate=" + customizeOnInstantiate
+ ", description=" + description + ", block=" + block + ", deploy=" + deploy + ", powerOn=" + powerOn + "]";
}
@Override
@ -171,6 +192,7 @@ public class InstantiateVAppTemplateOptions {
result = prime * result + (block ? 1231 : 1237);
result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode());
result = prime * result + (deploy ? 1231 : 1237);
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
result = prime * result + (powerOn ? 1231 : 1237);
return result;
@ -194,6 +216,11 @@ public class InstantiateVAppTemplateOptions {
return false;
if (deploy != other.deploy)
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (networkConfig == null) {
if (other.networkConfig != null)
return false;

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import static org.jclouds.vcloud.util.Utils.newReferenceType;
import java.util.List;
@ -72,44 +73,52 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
ovfDescriptorUploaded, children);
}
protected int depth = 0;
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
if (qName.endsWith("Children")) {
depth++;
if (depth == 2) {
if (equalsOrSuffix(qName, "Children")) {
inChildren = true;
} else if (qName.endsWith("Tasks")) {
} else if (equalsOrSuffix(qName, "Tasks")) {
inTasks = true;
}
}
if (inChildren) {
vmHandler.startElement(uri, localName, qName, attrs);
} else if (inTasks) {
taskHandler.startElement(uri, localName, qName, attrs);
} else if (qName.equals("VApp")) {
} else if (equalsOrSuffix(qName, "VApp")) {
template = newReferenceType(attributes);
if (attributes.containsKey("status"))
this.status = Status.fromValue(Integer.parseInt(attributes.get("status")));
} else if (qName.equals("Link") && "up".equals(attributes.get("rel"))) {
} else if (equalsOrSuffix(qName, "Link") && "up".equals(attributes.get("rel"))) {
vdc = newReferenceType(attributes);
}
}
public void endElement(String uri, String name, String qName) {
if (qName.endsWith("Children")) {
depth--;
if (depth == 1) {
if (equalsOrSuffix(qName, "Children")) {
inChildren = false;
this.children.add(vmHandler.getResult());
} else if (qName.endsWith("Tasks")) {
} else if (equalsOrSuffix(qName, "Tasks")) {
inTasks = false;
this.tasks.add(taskHandler.getResult());
} else if (equalsOrSuffix(qName, "Description")) {
description = SaxUtils.currentOrNull(currentText);
}
}
if (inChildren) {
vmHandler.endElement(uri, name, qName);
} else if (inTasks) {
taskHandler.endElement(uri, name, qName);
} else if (qName.equals("Description")) {
description = currentOrNull();
} else if (qName.equals("ovfDescriptorUploaded")) {
ovfDescriptorUploaded = Boolean.parseBoolean(currentOrNull());
} else if (equalsOrSuffix(qName, "ovfDescriptorUploaded")) {
ovfDescriptorUploaded = Boolean.parseBoolean(SaxUtils.currentOrNull(currentText));
}
currentText = new StringBuilder();
}
@ -122,8 +131,4 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
vmHandler.characters(ch, start, length);
}
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
}

View File

@ -43,6 +43,7 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
@ -54,9 +55,10 @@ import com.google.inject.Guice;
import com.google.inject.Module;
/**
* This tests that we can use guest customization as an alternative to bootstrapping with ssh. There
* are a few advantages to this, including the fact that it can work inside google appengine where
* network sockets (ssh:22) are prohibited.
* This tests that we can use guest customization as an alternative to
* bootstrapping with ssh. There are a few advantages to this, including the
* fact that it can work inside google appengine where network sockets (ssh:22)
* are prohibited.
*
* @author Adrian Cole
*/
@ -117,7 +119,8 @@ public class VCloudGuestCustomizationLiveTest {
return new JschSshClientModule();
}
// make sure the script has a lot of screwy characters, knowing our parser throws-out \r
// make sure the script has a lot of screwy characters, knowing our parser
// throws-out \r
private String iLoveAscii = "I '\"love\"' {asc|!}*&";
String script = "cat > /root/foo.txt<<EOF\n" + iLoveAscii + "\nEOF\n";
@ -129,11 +132,13 @@ public class VCloudGuestCustomizationLiveTest {
TemplateOptions options = client.templateOptions();
options.as(VCloudTemplateOptions.class).customizationScript(script);
options.as(VCloudTemplateOptions.class).description(group);
node = getOnlyElement(client.createNodesInGroup(group, 1, options));
Vm vm = Iterables.get(
((VCloudClient) client.getContext().getProviderSpecificContext().getApi()).getVApp(node.getUri())
.getChildren(), 0);
VApp vapp = ((VCloudClient) client.getContext().getProviderSpecificContext().getApi()).getVApp(node.getUri());
assertEquals(vapp.getDescription(), group);
Vm vm = Iterables.get(vapp.getChildren(), 0);
String apiOutput = vm.getGuestCustomizationSection().getCustomizationScript();
checkApiOutput(apiOutput);
@ -161,7 +166,8 @@ public class VCloudGuestCustomizationLiveTest {
}
protected void checkApiOutput1_0_1(String apiOutput) {
// in 1.0.1, vcloud director seems to pass through characters via api flawlessly
// in 1.0.1, vcloud director seems to pass through characters via api
// flawlessly
assertEquals(apiOutput, script);
}

View File

@ -94,15 +94,47 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object>of()).atLeastOnce();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(new InstantiateVAppTemplateOptions()))
.atLeastOnce();
request.setPayload(expected);
expect(template.getNetworkSection()).andReturn(net).atLeastOnce();
expect(net.getNetworks())
.andReturn(
ImmutableSet
.<org.jclouds.ovf.Network> of(new org.jclouds.ovf.Network(
"vAppNet-vApp Internal", null)));
expect(net.getNetworks()).andReturn(
ImmutableSet.<org.jclouds.ovf.Network> of(new org.jclouds.ovf.Network("vAppNet-vApp Internal", null)));
replay(request);
replay(template);
replay(net);
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", templateUri.toASCIIString());
binder.bindToRequest(request, map);
verify(request);
verify(template);
verify(net);
}
public void testDescription() throws IOException {
URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
VAppTemplate template = createMock(VAppTemplate.class);
VCloudNetworkSection net = createMock(VCloudNetworkSection.class);
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-description.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(
ImmutableList.<Object> of(new InstantiateVAppTemplateOptions().description("my foo"))).atLeastOnce();
request.setPayload(expected);
expect(template.getNetworkSection()).andReturn(net).atLeastOnce();
expect(net.getNetworks()).andReturn(
ImmutableSet.<org.jclouds.ovf.Network> of(new org.jclouds.ovf.Network("vAppNet-vApp Internal", null)));
replay(request);
replay(template);
@ -130,7 +162,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object>of()).atLeastOnce();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
request.setPayload(expected);
replay(request);
@ -156,7 +188,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object>of( options)).atLeastOnce();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
@ -176,14 +208,14 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
VAppTemplate template = null;
InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED));
InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("aloha",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED));
String expected = Strings2.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(ImmutableList.<Object>of( options)).atLeastOnce();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
@ -205,20 +237,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
VCloudNetworkSection net = createMock(VCloudNetworkSection.class);
InstantiateVAppTemplateOptions options = customizeOnInstantiate(true);
String expected = Strings2
.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-customization.xml"));
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
"/instantiationparams-customization.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object>of( options)).atLeastOnce();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
expect(template.getNetworkSection()).andReturn(net).atLeastOnce();
expect(net.getNetworks())
.andReturn(
ImmutableSet
.<org.jclouds.ovf.Network> of(new org.jclouds.ovf.Network(
"vAppNet-vApp Internal", null)));
expect(net.getNetworks()).andReturn(
ImmutableSet.<org.jclouds.ovf.Network> of(new org.jclouds.ovf.Network("vAppNet-vApp Internal", null)));
replay(request);
replay(template);

View File

@ -21,6 +21,7 @@ package org.jclouds.vcloud.compute.options;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.authorizePublicKey;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.blockOnPort;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.customizationScript;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.description;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.inboundPorts;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.installPrivateKey;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.ipAddressAllocationMode;
@ -34,7 +35,8 @@ import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
import org.testng.annotations.Test;
/**
* Tests possible uses of VCloudTemplateOptions and VCloudTemplateOptions.Builder.*
* Tests possible uses of VCloudTemplateOptions and
* VCloudTemplateOptions.Builder.*
*
* @author Adrian Cole
*/
@ -82,6 +84,19 @@ public class VCloudTemplateOptionsTest {
assertEquals(options.getCustomizationScript(), "mykeypair");
}
@Test
public void testdescription() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.description("mykeypair");
assertEquals(options.getDescription(), "mykeypair");
}
@Test
public void testdescriptionStatic() {
VCloudTemplateOptions options = description("mykeypair");
assertEquals(options.getDescription(), "mykeypair");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testcustomizationScriptNPE() {
customizationScript(null);

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.options;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.description;
import static org.testng.Assert.assertEquals;
import java.net.URI;
@ -74,4 +75,16 @@ public class InstantiateVAppTemplateOptionsTest {
assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true));
}
@Test
public void testDescription() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.description("foo");
assertEquals(options.getDescription(), "foo");
}
@Test
public void testDescriptionStatic() {
InstantiateVAppTemplateOptions options = description("foo");
assertEquals(options.getDescription(), "foo");
}
}

View File

@ -61,6 +61,7 @@ public class VAppHandlerTest {
Factory factory = injector.getInstance(ParseSax.Factory.class);
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
assertEquals(result.getName(), "vApp_acole_2");
assertEquals(result.getDescription(), "foo");
assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml");
assertEquals(result.getStatus(), Status.OFF);
@ -68,7 +69,6 @@ public class VAppHandlerTest {
result.getVDC(),
new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439")));
assertEquals(result.getDescription(), null);
assertEquals(result.getTasks(), ImmutableList.of());
assert result.isOvfDescriptorUploaded();
Vm vm = Iterables.getOnlyElement(result.getChildren());

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"><Description>my foo</Description><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

@ -23,7 +23,7 @@
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320" />
<Link rel="remove"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320" />
<Description />
<Description>foo</Description>
<LeaseSettingsSection
type="application/vnd.vmware.vcloud.leaseSettingsSection+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320/leaseSettingsSection/"