mirror of https://github.com/apache/jclouds.git
Adding ability to specify account and domain when creating CloudStack instances
This commit is contained in:
parent
3cc2a25292
commit
77c941ce3f
|
@ -60,7 +60,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();
|
||||
|
@ -78,6 +80,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);
|
||||
}
|
||||
}
|
||||
|
@ -167,6 +171,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 {
|
||||
|
@ -235,6 +264,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
|
||||
|
||||
/**
|
||||
|
|
|
@ -126,6 +126,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),
|
||||
|
@ -145,6 +146,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);
|
||||
|
||||
|
@ -387,4 +394,4 @@ public class CloudStackComputeServiceAdapter implements
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -175,6 +177,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 {
|
||||
|
|
Loading…
Reference in New Issue