Adding ability to specify account and domain when creating CloudStack instances

This commit is contained in:
Andrew Bayer 2012-11-03 12:07:11 -07:00 committed by Adrian Cole
parent f4edcff226
commit bdb7b7b2c5
3 changed files with 67 additions and 1 deletions

View File

@ -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
/**

View File

@ -125,6 +125,7 @@ public class CloudStackComputeServiceAdapter implements
@Override
public NodeAndInitialCredentials<VirtualMachine> 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);

View File

@ -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 {