mirror of https://github.com/apache/jclouds.git
update CloudstackTemplateOptions pattern
This commit is contained in:
parent
c10540b04d
commit
a1f6b7ebf2
|
@ -18,14 +18,21 @@ package org.jclouds.cloudstack.compute.options;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
/**
|
||||
* Contains options supported by the
|
||||
|
@ -48,18 +55,136 @@ import com.google.common.collect.Sets;
|
|||
*/
|
||||
public class CloudStackTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
|
||||
protected Set<String> securityGroupIds = Sets.<String> newLinkedHashSet();
|
||||
protected Map<String, String> ipsToNetworks = Maps.<String, String>newLinkedHashMap();
|
||||
protected String ipOnDefaultNetwork;
|
||||
protected String keyPair;
|
||||
protected boolean setupStaticNat = true;
|
||||
protected String account;
|
||||
protected String domainId;
|
||||
protected boolean generateKeyPair = false;
|
||||
protected boolean generateSecurityGroup = false;
|
||||
protected String diskOfferingId;
|
||||
protected int dataDiskSize;
|
||||
protected byte[] unencodedData;
|
||||
private Set<String> securityGroupIds = ImmutableSet.of();
|
||||
private Map<String, String> ipsToNetworks = ImmutableMap.of();
|
||||
private String ipOnDefaultNetwork;
|
||||
private String keyPair;
|
||||
private boolean setupStaticNat = true;
|
||||
private String account;
|
||||
private String domainId;
|
||||
private boolean generateKeyPair = false;
|
||||
private boolean generateSecurityGroup = false;
|
||||
private String diskOfferingId;
|
||||
private int dataDiskSize;
|
||||
private byte[] userData;
|
||||
|
||||
public CloudStackTemplateOptions securityGroupIds(Iterable<String> securityGroupIds) {
|
||||
this.securityGroupIds = ImmutableSet.copyOf(securityGroupIds);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions ipsToNetworks(Map<String, String> ipsToNetworks) {
|
||||
this.ipsToNetworks = ImmutableMap.copyOf(ipsToNetworks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions ipOnDefaultNetwork(String ipOnDefaultNetwork) {
|
||||
this.ipOnDefaultNetwork = ipOnDefaultNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions keyPair(String keyPair) {
|
||||
this.keyPair = keyPair;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
this.setupStaticNat = setupStaticNat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions domainId(String domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions generateKeyPair(boolean generateKeyPair) {
|
||||
this.generateKeyPair = generateKeyPair;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions generateSecurityGroup(boolean generateSecurityGroup) {
|
||||
this.generateSecurityGroup = generateSecurityGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions diskOfferingId(String diskOfferingId) {
|
||||
this.diskOfferingId = diskOfferingId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions dataDiskSize(int dataDiskSize) {
|
||||
this.dataDiskSize = dataDiskSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions userData(byte[] userData) {
|
||||
this.userData = userData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions userData(String userData) {
|
||||
this.userData = checkNotNull(userData, "userdata").getBytes(Charsets.UTF_8);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions userData(URL userDataUrl) throws IOException {
|
||||
this.userData = Resources.toString(checkNotNull(userDataUrl, "userDataUrl"), Charsets.UTF_8).getBytes(Charsets.UTF_8);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<String> getSecurityGroupIds() {
|
||||
return securityGroupIds;
|
||||
}
|
||||
|
||||
public Map<String, String> getIpsToNetworks() {
|
||||
return ipsToNetworks;
|
||||
}
|
||||
|
||||
public String getIpOnDefaultNetwork() {
|
||||
return ipOnDefaultNetwork;
|
||||
}
|
||||
|
||||
public String getKeyPair() {
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
public boolean shouldSetupStaticNat() {
|
||||
return setupStaticNat;
|
||||
}
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public String getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateKeyPair() {
|
||||
return generateKeyPair;
|
||||
}
|
||||
|
||||
public boolean shouldGenerateSecurityGroup() {
|
||||
return generateSecurityGroup;
|
||||
}
|
||||
|
||||
public String getDiskOfferingId() {
|
||||
return diskOfferingId;
|
||||
}
|
||||
|
||||
public int getDataDiskSize() {
|
||||
return dataDiskSize;
|
||||
}
|
||||
|
||||
public byte[] getUserData() {
|
||||
return userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudStackTemplateOptions clone() {
|
||||
|
@ -73,209 +198,136 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
super.copyTo(to);
|
||||
if (to instanceof CloudStackTemplateOptions) {
|
||||
CloudStackTemplateOptions eTo = CloudStackTemplateOptions.class.cast(to);
|
||||
eTo.securityGroupIds(this.securityGroupIds);
|
||||
eTo.ipsToNetworks(this.ipsToNetworks);
|
||||
eTo.ipOnDefaultNetwork(this.ipOnDefaultNetwork);
|
||||
eTo.keyPair(this.keyPair);
|
||||
eTo.generateKeyPair(shouldGenerateKeyPair());
|
||||
eTo.generateSecurityGroup(shouldGenerateSecurityGroup());
|
||||
eTo.account(this.account);
|
||||
eTo.domainId(this.domainId);
|
||||
eTo.securityGroupIds(securityGroupIds);
|
||||
eTo.ipsToNetworks(ipsToNetworks);
|
||||
eTo.ipOnDefaultNetwork(ipOnDefaultNetwork);
|
||||
eTo.keyPair(keyPair);
|
||||
eTo.generateKeyPair(generateKeyPair);
|
||||
eTo.generateSecurityGroup(generateSecurityGroup);
|
||||
eTo.account(account);
|
||||
eTo.domainId(domainId);
|
||||
eTo.setupStaticNat(setupStaticNat);
|
||||
eTo.diskOfferingId(diskOfferingId);
|
||||
eTo.dataDiskSize(dataDiskSize);
|
||||
eTo.userData(unencodedData);
|
||||
eTo.userData(userData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.options.DeployVirtualMachineOptions#diskOfferingId
|
||||
*/
|
||||
public CloudStackTemplateOptions diskOfferingId(String diskOfferingId) {
|
||||
this.diskOfferingId = diskOfferingId;
|
||||
return this;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof CloudStackTemplateOptions)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
CloudStackTemplateOptions that = (CloudStackTemplateOptions) o;
|
||||
return setupStaticNat == that.setupStaticNat &&
|
||||
generateKeyPair == that.generateKeyPair &&
|
||||
generateSecurityGroup == that.generateSecurityGroup &&
|
||||
dataDiskSize == that.dataDiskSize &&
|
||||
Objects.equal(securityGroupIds, that.securityGroupIds) &&
|
||||
Objects.equal(ipsToNetworks, that.ipsToNetworks) &&
|
||||
Objects.equal(ipOnDefaultNetwork, that.ipOnDefaultNetwork) &&
|
||||
Objects.equal(keyPair, that.keyPair) &&
|
||||
Objects.equal(account, that.account) &&
|
||||
Objects.equal(domainId, that.domainId) &&
|
||||
Objects.equal(diskOfferingId, that.diskOfferingId) &&
|
||||
Arrays.equals(userData, that.userData);
|
||||
}
|
||||
|
||||
public String getDiskOfferingId() {
|
||||
return diskOfferingId;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(super.hashCode(), securityGroupIds, ipsToNetworks, ipOnDefaultNetwork, keyPair, setupStaticNat, account, domainId, generateKeyPair, generateSecurityGroup, diskOfferingId, dataDiskSize, Arrays.hashCode(userData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#dataDiskSize
|
||||
*/
|
||||
public CloudStackTemplateOptions dataDiskSize(int dataDiskSize) {
|
||||
this.dataDiskSize = dataDiskSize;
|
||||
return this;
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("securityGroupIds", securityGroupIds)
|
||||
.add("ipsToNetworks", ipsToNetworks)
|
||||
.add("ipOnDefaultNetwork", ipOnDefaultNetwork)
|
||||
.add("keyPair", keyPair)
|
||||
.add("setupStaticNat", setupStaticNat)
|
||||
.add("account", account)
|
||||
.add("domainId", domainId)
|
||||
.add("generateKeyPair", generateKeyPair)
|
||||
.add("generateSecurityGroup", generateSecurityGroup)
|
||||
.add("diskOfferingId", diskOfferingId)
|
||||
.add("dataDiskSize", dataDiskSize)
|
||||
.add("userData", userData)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public int getDataDiskSize() {
|
||||
return dataDiskSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#userData
|
||||
*/
|
||||
public CloudStackTemplateOptions userData(byte[] unencodedData) {
|
||||
this.unencodedData = unencodedData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] getUserData() {
|
||||
return unencodedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#securityGroupId
|
||||
*/
|
||||
public CloudStackTemplateOptions securityGroupId(String securityGroupId) {
|
||||
this.securityGroupIds.add(securityGroupId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#securityGroupIds
|
||||
*/
|
||||
public CloudStackTemplateOptions securityGroupIds(Iterable<String> securityGroupIds) {
|
||||
Iterables.addAll(this.securityGroupIds, checkNotNull(securityGroupIds, "securityGroupIds was null"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<String> getSecurityGroupIds() {
|
||||
return securityGroupIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #shouldGenerateKeyPair()
|
||||
*/
|
||||
public CloudStackTemplateOptions generateSecurityGroup(boolean enable) {
|
||||
this.generateSecurityGroup = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if auto generation of keypairs is enabled
|
||||
*/
|
||||
public boolean shouldGenerateSecurityGroup() {
|
||||
return generateSecurityGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See TemplateOptions#networks
|
||||
* @see DeployVirtualMachineOptions#networkId
|
||||
*/
|
||||
@Deprecated
|
||||
public CloudStackTemplateOptions networkId(String networkId) {
|
||||
this.networks.add(networkId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See TemplateOptions#networks
|
||||
* @see DeployVirtualMachineOptions#networkIds
|
||||
*/
|
||||
@Deprecated
|
||||
public CloudStackTemplateOptions networkIds(Iterable<String> networkIds) {
|
||||
Iterables.addAll(this.networks, checkNotNull(networkIds, "networkIds was null"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See TemplateOptions#getNetworks
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<String> getNetworkIds() {
|
||||
return this.getNetworks();
|
||||
}
|
||||
|
||||
public CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
this.setupStaticNat = setupStaticNat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean shouldSetupStaticNat() {
|
||||
return this.setupStaticNat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#ipOnDefaultNetwork
|
||||
*/
|
||||
public CloudStackTemplateOptions ipOnDefaultNetwork(String ipOnDefaultNetwork) {
|
||||
this.ipOnDefaultNetwork = ipOnDefaultNetwork;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getIpOnDefaultNetwork() {
|
||||
return ipOnDefaultNetwork;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#ipOnDefaultNetwork(String)
|
||||
*/
|
||||
public CloudStackTemplateOptions ipsToNetworks(Map<String, String> ipsToNetworks) {
|
||||
this.ipsToNetworks.putAll(ipsToNetworks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getIpsToNetworks() {
|
||||
return ipsToNetworks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DeployVirtualMachineOptions#keyPair(String)
|
||||
*/
|
||||
public CloudStackTemplateOptions keyPair(String keyPair) {
|
||||
this.keyPair = keyPair;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getKeyPair() {
|
||||
return keyPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #shouldGenerateKeyPair()
|
||||
*/
|
||||
public CloudStackTemplateOptions generateKeyPair(boolean enable) {
|
||||
this.generateKeyPair = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if auto generation of keypairs is enabled
|
||||
*/
|
||||
public boolean shouldGenerateKeyPair() {
|
||||
return generateKeyPair;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#securityGroupIds
|
||||
*/
|
||||
public static CloudStackTemplateOptions securityGroupIds(Iterable<String> securityGroupIds) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.securityGroupIds(securityGroupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#ipsToNetworks
|
||||
*/
|
||||
public static CloudStackTemplateOptions ipsToNetworks(Map<String, String> ipToNetworkMap) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.ipsToNetworks(ipToNetworkMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#ipOnDefaultNetwork
|
||||
*/
|
||||
public static CloudStackTemplateOptions ipOnDefaultNetwork(String ipAddress) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.ipOnDefaultNetwork(ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#keyPair
|
||||
*/
|
||||
public static CloudStackTemplateOptions keyPair(String keyPair) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.keyPair(keyPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#setupStaticNat
|
||||
*/
|
||||
public static CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.setupStaticNat(setupStaticNat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#generateKeyPair(boolean)
|
||||
*/
|
||||
public static CloudStackTemplateOptions generateKeyPair(boolean enable) {
|
||||
return new CloudStackTemplateOptions().generateKeyPair(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#generateSecurityGroup(boolean)
|
||||
*/
|
||||
public static CloudStackTemplateOptions generateSecurityGroup(boolean enable) {
|
||||
return new CloudStackTemplateOptions().generateSecurityGroup(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#diskOfferingId
|
||||
*/
|
||||
|
@ -295,170 +347,17 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
/**
|
||||
* @see CloudStackTemplateOptions#userData
|
||||
*/
|
||||
public static CloudStackTemplateOptions userData(byte[] unencodedData) {
|
||||
public static CloudStackTemplateOptions userData(byte[] userData) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.userData(unencodedData);
|
||||
return options.userData(userData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#securityGroupId
|
||||
*/
|
||||
public static CloudStackTemplateOptions securityGroupId(String id) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.securityGroupId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#securityGroupIds
|
||||
*/
|
||||
public static CloudStackTemplateOptions securityGroupIds(Iterable<String> securityGroupIds) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.securityGroupIds(securityGroupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#shouldGenerateSecurityGroup()
|
||||
*/
|
||||
public static CloudStackTemplateOptions generateSecurityGroup(boolean enable) {
|
||||
return new CloudStackTemplateOptions().generateSecurityGroup(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated See TemplateOptions#networks
|
||||
* @see CloudStackTemplateOptions#networkId
|
||||
*/
|
||||
@Deprecated
|
||||
public static CloudStackTemplateOptions networkId(String id) {
|
||||
return networks(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated see TemplateOptions#networks
|
||||
* @see CloudStackTemplateOptions#networkIds
|
||||
*/
|
||||
@Deprecated
|
||||
public static CloudStackTemplateOptions networkIds(Iterable<String> networkIds) {
|
||||
return networks(networkIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#ipOnDefaultNetwork
|
||||
*/
|
||||
public static CloudStackTemplateOptions ipOnDefaultNetwork(String ipAddress) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.ipOnDefaultNetwork(ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#ipsToNetworks
|
||||
*/
|
||||
public static CloudStackTemplateOptions ipsToNetworks(Map<String, String> ipToNetworkMap) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.ipsToNetworks(ipToNetworkMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#setupStaticNat
|
||||
*/
|
||||
public static CloudStackTemplateOptions setupStaticNat(boolean setupStaticNat) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.setupStaticNat(setupStaticNat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#keyPair
|
||||
*/
|
||||
public static CloudStackTemplateOptions keyPair(String keyPair) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return options.keyPair(keyPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CloudStackTemplateOptions#shouldGenerateKeyPair()
|
||||
*/
|
||||
public static CloudStackTemplateOptions generateKeyPair(boolean enable) {
|
||||
return new CloudStackTemplateOptions().generateKeyPair(enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#inboundPorts(int...)
|
||||
*/
|
||||
public static CloudStackTemplateOptions inboundPorts(int... ports) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.inboundPorts(ports));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#blockOnPort(int, int)
|
||||
*/
|
||||
public static CloudStackTemplateOptions blockOnPort(int port, int seconds) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.blockOnPort(port, seconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#userMetadata(Map)
|
||||
*/
|
||||
public static CloudStackTemplateOptions userMetadata(Map<String, String> userMetadata) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.userMetadata(userMetadata));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#userMetadata(String, String)
|
||||
*/
|
||||
public static CloudStackTemplateOptions userMetadata(String key, String value) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.userMetadata(key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#nodeNames(Iterable)
|
||||
*/
|
||||
public static CloudStackTemplateOptions nodeNames(Iterable<String> nodeNames) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.nodeNames(nodeNames));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#networks(Iterable)
|
||||
*/
|
||||
public static CloudStackTemplateOptions networks(Iterable<String> networks) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.networks(networks));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#networks(String...)
|
||||
*/
|
||||
public static CloudStackTemplateOptions networks(String... networks) {
|
||||
CloudStackTemplateOptions options = new CloudStackTemplateOptions();
|
||||
return CloudStackTemplateOptions.class.cast(options.networks(networks));
|
||||
}
|
||||
}
|
||||
|
||||
// methods that only facilitate returning the correct object type
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#blockOnPort(int, int)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions blockOnPort(int port, int seconds) {
|
||||
|
@ -466,7 +365,7 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#inboundPorts(int...)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions inboundPorts(int... ports) {
|
||||
|
@ -474,7 +373,7 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#authorizePublicKey(String)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions authorizePublicKey(String publicKey) {
|
||||
|
@ -482,13 +381,93 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
}
|
||||
|
||||
/**
|
||||
* @see TemplateOptions#installPrivateKey(String)
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions installPrivateKey(String privateKey) {
|
||||
return CloudStackTemplateOptions.class.cast(super.installPrivateKey(privateKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||
return CloudStackTemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions dontAuthorizePublicKey() {
|
||||
return CloudStackTemplateOptions.class.cast(super.dontAuthorizePublicKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions nameTask(String name) {
|
||||
return CloudStackTemplateOptions.class.cast(super.nameTask(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions runAsRoot(boolean runAsRoot) {
|
||||
return CloudStackTemplateOptions.class.cast(super.runAsRoot(runAsRoot));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions runScript(Statement script) {
|
||||
return CloudStackTemplateOptions.class.cast(super.runScript(script));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials) {
|
||||
return CloudStackTemplateOptions.class.cast(super.overrideLoginCredentials(overridingCredentials));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions overrideLoginPassword(String password) {
|
||||
return CloudStackTemplateOptions.class.cast(super.overrideLoginPassword(password));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions overrideLoginPrivateKey(String privateKey) {
|
||||
return CloudStackTemplateOptions.class.cast(super.overrideLoginPrivateKey(privateKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions overrideLoginUser(String loginUser) {
|
||||
return CloudStackTemplateOptions.class.cast(super.overrideLoginUser(loginUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) {
|
||||
return CloudStackTemplateOptions.class.cast(super.overrideAuthenticateSudo(authenticateSudo));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -520,12 +499,4 @@ public class CloudStackTemplateOptions extends TemplateOptions implements Clonea
|
|||
public CloudStackTemplateOptions networks(Iterable<String> networks) {
|
||||
return CloudStackTemplateOptions.class.cast(super.networks(networks));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CloudStackTemplateOptions networks(String... networks) {
|
||||
return CloudStackTemplateOptions.class.cast(super.networks(networks));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,8 +205,7 @@ public class CloudStackComputeServiceAdapter implements
|
|||
options.keyPair(keyPair.getName());
|
||||
}
|
||||
} else if (templateOptions.shouldGenerateKeyPair()) {
|
||||
SshKeyPair keyPair = keyPairCache.getUnchecked(namingConvention.create()
|
||||
.sharedNameForGroup(group));
|
||||
SshKeyPair keyPair = keyPairCache.getUnchecked(namingConvention.create().sharedNameForGroup(group));
|
||||
keyPairCache.asMap().put(keyPair.getName(), keyPair);
|
||||
templateOptions.keyPair(keyPair.getName());
|
||||
options.keyPair(keyPair.getName());
|
||||
|
|
|
@ -16,13 +16,6 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.compute.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.collections.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.account;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.dataDiskSize;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.diskOfferingId;
|
||||
|
@ -32,14 +25,19 @@ import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.B
|
|||
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;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.networks;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupId;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.securityGroupIds;
|
||||
import static org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions.Builder.setupStaticNat;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.collections.Maps;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests possible uses of {@code CloudStackTemplateOptions} and
|
||||
|
@ -50,7 +48,7 @@ import static org.testng.Assert.fail;
|
|||
@Test(groups = "unit", testName = "CloudStackTemplateOptionsTest")
|
||||
public class CloudStackTemplateOptionsTest {
|
||||
//TODO: test clone();
|
||||
|
||||
|
||||
@Test
|
||||
public void testAs() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions();
|
||||
|
@ -63,18 +61,6 @@ public class CloudStackTemplateOptionsTest {
|
|||
assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityGroupId() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions().securityGroupId("3");
|
||||
assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityGroupIdStatic() {
|
||||
TemplateOptions options = securityGroupId("3");
|
||||
assertEquals(options.as(CloudStackTemplateOptions.class).getSecurityGroupIds(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityGroupIds() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions().securityGroupIds(ImmutableSet.of("3"));
|
||||
|
@ -120,24 +106,6 @@ public class CloudStackTemplateOptionsTest {
|
|||
assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkIdStatic() {
|
||||
TemplateOptions options = networks(ImmutableSet.of("3"));
|
||||
assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkIds() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions().networks(ImmutableSet.of("3"));
|
||||
assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkIdsStatic() {
|
||||
TemplateOptions options = networks(ImmutableSet.of("3"));
|
||||
assertEquals(options.as(CloudStackTemplateOptions.class).getNetworks(), ImmutableSet.of("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIpOnDefaultNetwork() {
|
||||
TemplateOptions options = new CloudStackTemplateOptions().ipOnDefaultNetwork("10.0.0.1");
|
||||
|
@ -248,14 +216,4 @@ public class CloudStackTemplateOptionsTest {
|
|||
assertEquals(options.as(CloudStackTemplateOptions.class).getDomainId(), "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecurityGroupIdsNullHasDecentMessage() {
|
||||
try {
|
||||
new CloudStackTemplateOptions().securityGroupIds(null);
|
||||
fail("should NPE");
|
||||
} catch (NullPointerException e) {
|
||||
assertEquals(e.getMessage(), "securityGroupIds was null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,18 +16,20 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.compute.strategy;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.cloudstack.compute.options.CloudStackTemplateOptions;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.NetworkService;
|
||||
import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@Test(singleThreaded = true, testName = "OptionsConverterTest")
|
||||
public class OptionsConverterTest {
|
||||
|
@ -41,7 +43,7 @@ public class OptionsConverterTest {
|
|||
public void testBasicNetworkOptionsConverter() {
|
||||
BasicNetworkOptionsConverter converter = new BasicNetworkOptionsConverter();
|
||||
|
||||
CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupId("42").networks("46");
|
||||
CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupIds(ImmutableList.of("42")).networks(ImmutableList.of("46"));
|
||||
DeployVirtualMachineOptions optionsOut = new DeployVirtualMachineOptions();
|
||||
|
||||
DeployVirtualMachineOptions optionsOut2 = converter.apply(optionsIn, EMPTY_NETWORKS_MAP, ZONE_ID, optionsOut);
|
||||
|
@ -55,7 +57,7 @@ public class OptionsConverterTest {
|
|||
public void testAdvancedSecurityGroupsNotAllowed() {
|
||||
boolean exceptionThrown = false;
|
||||
AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter();
|
||||
CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupId("42");
|
||||
CloudStackTemplateOptions optionsIn = CloudStackTemplateOptions.Builder.securityGroupIds(ImmutableList.of("42"));
|
||||
|
||||
try {
|
||||
converter.apply(optionsIn, EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
|
@ -69,7 +71,7 @@ public class OptionsConverterTest {
|
|||
@Test
|
||||
public void testAdvancedExplicitNetworkSelection() {
|
||||
AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter();
|
||||
DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.Builder.networks("42"),
|
||||
DeployVirtualMachineOptions optionsActual = converter.apply(new CloudStackTemplateOptions().networks(ImmutableList.of("42")),
|
||||
EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("42");
|
||||
assertEquals(optionsActual, optionsExpected);
|
||||
|
@ -82,7 +84,7 @@ public class OptionsConverterTest {
|
|||
Network eligibleNetwork = Network.builder()
|
||||
.id("25").zoneId(ZONE_ID).isDefault(true).services(ImmutableSet.of(firewallServiceWithStaticNat))
|
||||
.build();
|
||||
DeployVirtualMachineOptions optionsActual = converter.apply(CloudStackTemplateOptions.NONE,
|
||||
DeployVirtualMachineOptions optionsActual = converter.apply(new CloudStackTemplateOptions(),
|
||||
ImmutableMap.of(eligibleNetwork.getId(), eligibleNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
DeployVirtualMachineOptions optionsExpected = DeployVirtualMachineOptions.Builder.networkId("25");
|
||||
assertEquals(optionsActual, optionsExpected);
|
||||
|
@ -93,7 +95,7 @@ public class OptionsConverterTest {
|
|||
AdvancedNetworkOptionsConverter converter = new AdvancedNetworkOptionsConverter();
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
converter.apply(CloudStackTemplateOptions.NONE, EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
converter.apply(new CloudStackTemplateOptions(), EMPTY_NETWORKS_MAP, ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
|
@ -109,7 +111,7 @@ public class OptionsConverterTest {
|
|||
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
converter.apply(CloudStackTemplateOptions.NONE, ImmutableMap.of(unsuitableNetwork.getId(), unsuitableNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
converter.apply(new CloudStackTemplateOptions(), ImmutableMap.of(unsuitableNetwork.getId(), unsuitableNetwork), ZONE_ID, DeployVirtualMachineOptions.NONE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue