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
f4edcff226
commit
bdb7b7b2c5
|
@ -58,6 +58,8 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
||||||
protected String ipOnDefaultNetwork;
|
protected String ipOnDefaultNetwork;
|
||||||
protected String keyPair;
|
protected String keyPair;
|
||||||
protected boolean setupStaticNat = true;
|
protected boolean setupStaticNat = true;
|
||||||
|
protected String account;
|
||||||
|
protected String domainId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CloudStackTemplateOptions clone() {
|
public CloudStackTemplateOptions clone() {
|
||||||
|
@ -76,6 +78,8 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
||||||
eTo.ipsToNetworks(this.ipsToNetworks);
|
eTo.ipsToNetworks(this.ipsToNetworks);
|
||||||
eTo.ipOnDefaultNetwork(this.ipOnDefaultNetwork);
|
eTo.ipOnDefaultNetwork(this.ipOnDefaultNetwork);
|
||||||
eTo.keyPair(this.keyPair);
|
eTo.keyPair(this.keyPair);
|
||||||
|
eTo.account(this.account);
|
||||||
|
eTo.domainId(this.domainId);
|
||||||
eTo.setupStaticNat(setupStaticNat);
|
eTo.setupStaticNat(setupStaticNat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,6 +169,31 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
||||||
return keyPair;
|
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 final CloudStackTemplateOptions NONE = new CloudStackTemplateOptions();
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
@ -233,6 +262,22 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
||||||
return options.keyPair(keyPair);
|
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
|
// methods that only facilitate returning the correct object type
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -125,6 +125,7 @@ public class CloudStackComputeServiceAdapter implements
|
||||||
@Override
|
@Override
|
||||||
public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(String group, String name,
|
public NodeAndInitialCredentials<VirtualMachine> createNodeWithGroupEncodedIntoName(String group, String name,
|
||||||
org.jclouds.compute.domain.Template template) {
|
org.jclouds.compute.domain.Template template) {
|
||||||
|
|
||||||
checkNotNull(template, "template was null");
|
checkNotNull(template, "template was null");
|
||||||
checkNotNull(template.getOptions(), "template options was null");
|
checkNotNull(template.getOptions(), "template options was null");
|
||||||
checkArgument(template.getOptions().getClass().isAssignableFrom(CloudStackTemplateOptions.class),
|
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());
|
checkState(optionsConverters.containsKey(zone.getNetworkType()), "no options converter configured for network type %s", zone.getNetworkType());
|
||||||
DeployVirtualMachineOptions options = displayName(name).name(name);
|
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());
|
OptionsConverter optionsConverter = optionsConverters.get(zone.getNetworkType());
|
||||||
options = optionsConverter.apply(templateOptions, networks, zoneId, options);
|
options = optionsConverter.apply(templateOptions, networks, zoneId, options);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.compute.options;
|
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.ipOnDefaultNetwork;
|
||||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipsToNetworks;
|
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.ipsToNetworks;
|
||||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.keyPair;
|
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.keyPair;
|
||||||
|
@ -176,6 +178,18 @@ public class CloudStackTemplateOptionsTest {
|
||||||
assertEquals(options.as(CloudStackTemplateOptions.class).getKeyPair(), "test");
|
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
|
@Test
|
||||||
public void testSecurityGroupIdsNullHasDecentMessage() {
|
public void testSecurityGroupIdsNullHasDecentMessage() {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue