diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptions.java index 02067441a2..dfa2aac548 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptions.java @@ -58,7 +58,9 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea protected String ipOnDefaultNetwork; protected String keyPair; protected boolean setupStaticNat = true; - + protected String account; + protected String domainId; + @Override public CloudStackTemplateOptions clone() { CloudStackTemplateOptions options = new CloudStackTemplateOptions(); @@ -76,6 +78,8 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea eTo.ipsToNetworks(this.ipsToNetworks); eTo.ipOnDefaultNetwork(this.ipOnDefaultNetwork); eTo.keyPair(this.keyPair); + eTo.account(this.account); + eTo.domainId(this.domainId); eTo.setupStaticNat(setupStaticNat); } } @@ -165,6 +169,31 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea return keyPair; } + /** + * @see DeployVirtualMachineOptions#accountInDomain(String,String) + */ + public CloudStackTemplateOptions account(String account) { + this.account = account; + return this; + } + + public String getAccount() { + return account; + } + + /** + * @see DeployVirtualMachineOptions#accountInDomain(String,String) + * @see DeployVirtualMachineOptions#domainId(String) + */ + public CloudStackTemplateOptions domainId(String domainId) { + this.domainId = domainId; + return this; + } + + public String getDomainId() { + return domainId; + } + public static final CloudStackTemplateOptions NONE = new CloudStackTemplateOptions(); public static class Builder { @@ -233,6 +262,22 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea return options.keyPair(keyPair); } + /** + * @see CloudStackTemplateOptions#account + */ + public static CloudStackTemplateOptions account(String account) { + CloudStackTemplateOptions options = new CloudStackTemplateOptions(); + return options.account(account); + } + + /** + * @see CloudStackTemplateOptions#domainId + */ + public static CloudStackTemplateOptions domainId(String domainId) { + CloudStackTemplateOptions options = new CloudStackTemplateOptions(); + return options.domainId(domainId); + } + // methods that only facilitate returning the correct object type /** diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java index e9f13651a9..93de9d7742 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/strategy/CloudStackComputeServiceAdapter.java @@ -125,6 +125,7 @@ public class CloudStackComputeServiceAdapter implements @Override public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName(String group, String name, org.jclouds.compute.domain.Template template) { + checkNotNull(template, "template was null"); checkNotNull(template.getOptions(), "template options was null"); checkArgument(template.getOptions().getClass().isAssignableFrom(CloudStackTemplateOptions.class), @@ -144,6 +145,12 @@ public class CloudStackComputeServiceAdapter implements checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s", zone.getNetworkType()); DeployVirtualMachineOptions options = displayName(name).name(name); + if (templateOptions.getAccount() != null) { + options.accountInDomain(templateOptions.getAccount(), templateOptions.getDomainId()); + } else if (templateOptions.getDomainId() != null) { + options.domainId(templateOptions.getDomainId()); + } + OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType()); options = optionsConverter.apply(templateOptions, networks, zoneId, options); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java index 1308dbd7b1..c5599e7ff0 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/options/CloudStackTemplateOptionsTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.cloudstack.compute.options; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.account; +import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.domainId; import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipOnDefaultNetwork; import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipsToNetworks; import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.keyPair; @@ -176,6 +178,18 @@ public class CloudStackTemplateOptionsTest { assertEquals(options.as(CloudStackTemplateOptions.class).getKeyPair(), "test"); } + @Test + public void testAccount() { + TemplateOptions options = account("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getAccount(), "test"); + } + + @Test + public void testDomainId() { + TemplateOptions options = domainId("test"); + assertEquals(options.as(CloudStackTemplateOptions.class).getDomainId(), "test"); + } + @Test public void testSecurityGroupIdsNullHasDecentMessage() { try {