mirror of https://github.com/apache/jclouds.git
Issue 500: added options overrideLoginUserWith and overrideLoginCredentialWith
This commit is contained in:
parent
9892fb1d1b
commit
d7814821a3
|
@ -37,7 +37,6 @@ import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
|||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ComputationException;
|
||||
|
@ -59,25 +58,6 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
this.imageMap = imageMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||
super.copyTemplateOptions(from, to);
|
||||
if (from instanceof EC2TemplateOptions) {
|
||||
EC2TemplateOptions eFrom = EC2TemplateOptions.class.cast(from);
|
||||
EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to);
|
||||
if (eFrom.getGroupIds().size() > 0)
|
||||
eTo.securityGroups(eFrom.getGroupIds());
|
||||
if (eFrom.getKeyPair() != null)
|
||||
eTo.keyPair(eFrom.getKeyPair());
|
||||
if (eFrom.getBlockDeviceMappings().size() > 0)
|
||||
eTo.blockDeviceMappings(eFrom.getBlockDeviceMappings());
|
||||
if (!eFrom.shouldAutomaticallyCreateKeyPair())
|
||||
eTo.noKeyPair();
|
||||
if (eFrom.getUserData() != null)
|
||||
eTo.userData(eFrom.getUserData());
|
||||
}
|
||||
}
|
||||
|
||||
final Provider<Image> lazyImageProvider = new Provider<Image>() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,31 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class EC2TemplateOptions extends TemplateOptions {
|
||||
public class EC2TemplateOptions extends TemplateOptions implements Cloneable {
|
||||
@Override
|
||||
public EC2TemplateOptions clone() {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof EC2TemplateOptions) {
|
||||
EC2TemplateOptions eTo = EC2TemplateOptions.class.cast(to);
|
||||
if (getGroupIds().size() > 0)
|
||||
eTo.securityGroups(getGroupIds());
|
||||
if (getKeyPair() != null)
|
||||
eTo.keyPair(getKeyPair());
|
||||
if (getBlockDeviceMappings().size() > 0)
|
||||
eTo.blockDeviceMappings(getBlockDeviceMappings());
|
||||
if (!shouldAutomaticallyCreateKeyPair())
|
||||
eTo.noKeyPair();
|
||||
if (getUserData() != null)
|
||||
eTo.userData(getUserData());
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> groupIds = ImmutableSet.of();
|
||||
private String keyPair = null;
|
||||
|
@ -93,7 +117,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
*/
|
||||
public EC2TemplateOptions userData(byte[] unencodedData) {
|
||||
checkArgument(checkNotNull(unencodedData, "unencodedData").length <= 16 * 1024,
|
||||
"userData cannot be larger than 16kb");
|
||||
"userData cannot be larger than 16kb");
|
||||
this.userData = unencodedData;
|
||||
return this;
|
||||
}
|
||||
|
@ -122,16 +146,16 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
* Specifies the block device mappings to be used to run the instance
|
||||
*/
|
||||
public EC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId,
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
checkNotNull(deviceName, "deviceName cannot be null");
|
||||
Preconditions2.checkNotEmpty(deviceName, "deviceName must be non-empty");
|
||||
checkNotNull(snapshotId, "snapshotId cannot be null");
|
||||
Preconditions2.checkNotEmpty(snapshotId, "snapshotId must be non-empty");
|
||||
com.google.common.collect.ImmutableSet.Builder<BlockDeviceMapping> mappings = ImmutableSet
|
||||
.<BlockDeviceMapping> builder();
|
||||
.<BlockDeviceMapping> builder();
|
||||
mappings.addAll(blockDeviceMappings);
|
||||
MapEBSSnapshotToDevice mapping = new MapEBSSnapshotToDevice(deviceName, snapshotId, sizeInGib,
|
||||
deleteOnTermination);
|
||||
deleteOnTermination);
|
||||
mappings.add(mapping);
|
||||
blockDeviceMappings = mappings.build();
|
||||
return this;
|
||||
|
@ -145,7 +169,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
Preconditions2.checkNotEmpty(deviceName, "deviceName must be non-empty");
|
||||
|
||||
com.google.common.collect.ImmutableSet.Builder<BlockDeviceMapping> mappings = ImmutableSet
|
||||
.<BlockDeviceMapping> builder();
|
||||
.<BlockDeviceMapping> builder();
|
||||
mappings.addAll(blockDeviceMappings);
|
||||
MapNewVolumeToDevice mapping = new MapNewVolumeToDevice(deviceName, sizeInGib, deleteOnTermination);
|
||||
mappings.add(mapping);
|
||||
|
@ -163,7 +187,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
Preconditions2.checkNotEmpty(virtualName, "virtualName must be non-empty");
|
||||
|
||||
com.google.common.collect.ImmutableSet.Builder<BlockDeviceMapping> mappings = ImmutableSet
|
||||
.<BlockDeviceMapping> builder();
|
||||
.<BlockDeviceMapping> builder();
|
||||
mappings.addAll(blockDeviceMappings);
|
||||
MapEphemeralDeviceToDevice mapping = new MapEphemeralDeviceToDevice(deviceName, virtualName);
|
||||
mappings.add(mapping);
|
||||
|
@ -179,7 +203,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
Preconditions2.checkNotEmpty(deviceName, "deviceName must be non-empty");
|
||||
|
||||
com.google.common.collect.ImmutableSet.Builder<BlockDeviceMapping> mappings = ImmutableSet
|
||||
.<BlockDeviceMapping> builder();
|
||||
.<BlockDeviceMapping> builder();
|
||||
mappings.addAll(blockDeviceMappings);
|
||||
UnmapDeviceNamed mapping = new UnmapDeviceNamed(deviceName);
|
||||
mappings.add(mapping);
|
||||
|
@ -208,7 +232,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
* @see EC2TemplateOptions#mapEBSSnapshotToDeviceName
|
||||
*/
|
||||
public static EC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId,
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.mapEBSSnapshotToDeviceName(deviceName, snapshotId, sizeInGib, deleteOnTermination);
|
||||
}
|
||||
|
@ -217,7 +241,7 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
* @see EC2TemplateOptions#mapNewVolumeToDeviceName
|
||||
*/
|
||||
public static EC2TemplateOptions mapNewVolumeToDeviceName(String deviceName, int sizeInGib,
|
||||
boolean deleteOnTermination) {
|
||||
boolean deleteOnTermination) {
|
||||
EC2TemplateOptions options = new EC2TemplateOptions();
|
||||
return options.mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination);
|
||||
}
|
||||
|
@ -450,8 +474,8 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public EC2TemplateOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||
return EC2TemplateOptions.class.cast(super.withOverridingCredentials(overridingCredentials));
|
||||
public EC2TemplateOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
return EC2TemplateOptions.class.cast(super.overrideCredentialsWith(overridingCredentials));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -537,6 +561,6 @@ public class EC2TemplateOptions extends TemplateOptions {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[groupIds=" + groupIds + ", keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", userData="
|
||||
+ Arrays.toString(userData) + ", blockDeviceMappings=" + blockDeviceMappings + "]";
|
||||
+ Arrays.toString(userData) + ", blockDeviceMappings=" + blockDeviceMappings + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
|
|||
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
|
@ -49,18 +48,4 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
|
|||
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
|
||||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||
super.copyTemplateOptions(from, to);
|
||||
if (from instanceof VCloudTemplateOptions) {
|
||||
VCloudTemplateOptions eFrom = VCloudTemplateOptions.class.cast(from);
|
||||
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
|
||||
if (eFrom.getCustomizationScript() != null)
|
||||
eTo.customizationScript(eFrom.getCustomizationScript());
|
||||
if (eFrom.getIpAddressAllocationMode() != null)
|
||||
eTo.ipAddressAllocationMode(eFrom.getIpAddressAllocationMode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,25 @@ import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class VCloudTemplateOptions extends TemplateOptions {
|
||||
public class VCloudTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
@Override
|
||||
public VCloudTemplateOptions clone() {
|
||||
VCloudTemplateOptions options = new VCloudTemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof VCloudTemplateOptions) {
|
||||
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
|
||||
if (getCustomizationScript() != null)
|
||||
eTo.customizationScript(getCustomizationScript());
|
||||
if (getIpAddressAllocationMode() != null)
|
||||
eTo.ipAddressAllocationMode(getIpAddressAllocationMode());
|
||||
}
|
||||
}
|
||||
|
||||
private String customizationScript = null;
|
||||
private IpAddressAllocationMode ipAddressAllocationMode = null;
|
||||
|
|
|
@ -45,7 +45,25 @@ import org.jclouds.util.Preconditions2;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
||||
public class TerremarkVCloudTemplateOptions extends TemplateOptions implements Cloneable {
|
||||
@Override
|
||||
public TerremarkVCloudTemplateOptions clone() {
|
||||
TerremarkVCloudTemplateOptions options = new TerremarkVCloudTemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof TerremarkVCloudTemplateOptions) {
|
||||
TerremarkVCloudTemplateOptions eTo = TerremarkVCloudTemplateOptions.class.cast(to);
|
||||
if (noKeyPair)
|
||||
eTo.noKeyPair();
|
||||
if (keyPair != null)
|
||||
eTo.keyPair = keyPair;
|
||||
}
|
||||
}
|
||||
|
||||
private String keyPair = null;
|
||||
private boolean noKeyPair;
|
||||
|
@ -276,9 +294,9 @@ public class TerremarkVCloudTemplateOptions extends TemplateOptions {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "TerremarkVCloudTemplateOptions [keyPair=" + keyPair + ", noKeyPair=" + noKeyPair + ", inboundPorts="
|
||||
+ Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
|
||||
+ (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", metadata/details: " + includeMetadata + "]";
|
||||
+ Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
|
||||
+ (publicKey != null) + ", runScript=" + (script != null) + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", metadata/details: " + includeMetadata + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|||
import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
@ -420,6 +419,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
public TemplateBuilder fromTemplate(Template template) {
|
||||
fromHardware(template.getHardware());
|
||||
fromImage(template.getImage());
|
||||
options(template.getOptions());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -810,33 +810,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
|
|||
@Override
|
||||
public TemplateBuilder options(TemplateOptions options) {
|
||||
this.options = optionsProvider.get();
|
||||
copyTemplateOptions(checkNotNull(options, "options"), this.options);
|
||||
checkNotNull(options, "options").copyTo(this.options);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||
if (!Arrays.equals(to.getInboundPorts(), from.getInboundPorts()))
|
||||
to.inboundPorts(from.getInboundPorts());
|
||||
if (from.getRunScript() != null)
|
||||
to.runScript(from.getRunScript());
|
||||
if (from.getPrivateKey() != null)
|
||||
to.installPrivateKey(from.getPrivateKey());
|
||||
if (from.getPublicKey() != null)
|
||||
to.authorizePublicKey(from.getPublicKey());
|
||||
if (from.getPort() != -1)
|
||||
to.blockOnPort(from.getPort(), from.getSeconds());
|
||||
if (from.isIncludeMetadata())
|
||||
to.withMetadata();
|
||||
if (!from.shouldBlockUntilRunning())
|
||||
to.blockUntilRunning(false);
|
||||
if (!from.shouldBlockOnComplete())
|
||||
to.blockOnComplete(false);
|
||||
if (from.getOverrideCredentials() != null)
|
||||
to.withOverridingCredentials(from.getOverrideCredentials());
|
||||
if (from.getTaskName() != null)
|
||||
to.nameTask(from.getTaskName());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean nothingChangedExceptOptions() {
|
||||
return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null
|
||||
|
|
|
@ -54,8 +54,8 @@ public class RunScriptOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Credentials getOverrideCredentials() {
|
||||
return delegate.getOverrideCredentials();
|
||||
public Credentials getOverridingCredentials() {
|
||||
return delegate.getOverridingCredentials();
|
||||
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,22 @@ public class RunScriptOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RunScriptOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||
public RunScriptOptions overrideLoginUserWith(String loginUser) {
|
||||
throw new IllegalArgumentException("loginUser is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunScriptOptions overrideLoginCredentialWith(String loginCredential) {
|
||||
throw new IllegalArgumentException("loginCredential is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunScriptOptions wrapInInitScript(boolean wrapInInitScript) {
|
||||
throw new IllegalArgumentException("wrapInInitScript is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunScriptOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
throw new IllegalArgumentException("overridingCredentials is immutable");
|
||||
}
|
||||
|
||||
|
@ -120,17 +135,31 @@ public class RunScriptOptions {
|
|||
protected boolean blockOnComplete = true;
|
||||
protected boolean wrapInInitScript = true;
|
||||
|
||||
public RunScriptOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||
public RunScriptOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
checkNotNull(overridingCredentials, "overridingCredentials");
|
||||
checkNotNull(overridingCredentials.identity, "overridingCredentials.identity");
|
||||
checkNotNull(overridingCredentials.credential, "overridingCredentials.key");
|
||||
this.overridingCredentials = overridingCredentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunScriptOptions overrideLoginUserWith(String loginUser) {
|
||||
checkNotNull(loginUser, "loginUser");
|
||||
org.jclouds.domain.Credentials.Builder<? extends Credentials> builder = overridingCredentials != null ? overridingCredentials
|
||||
.toBuilder() : new Credentials.Builder<Credentials>();
|
||||
this.overridingCredentials = builder.identity(loginUser).build();
|
||||
return this;
|
||||
}
|
||||
|
||||
public RunScriptOptions overrideLoginCredentialWith(String loginCredential) {
|
||||
checkNotNull(loginCredential, "loginCredential");
|
||||
org.jclouds.domain.Credentials.Builder<? extends Credentials> builder = overridingCredentials != null ? overridingCredentials
|
||||
.toBuilder() : new Credentials.Builder<Credentials>();
|
||||
this.overridingCredentials = builder.credential(loginCredential).build();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return What to call the task relating to this script; default {@code
|
||||
* jclouds-script-timestamp} where timestamp is millis since epoch
|
||||
* @return What to call the task relating to this script; default
|
||||
* {@code jclouds-script-timestamp} where timestamp is millis since epoch
|
||||
*
|
||||
*/
|
||||
public RunScriptOptions nameTask(String name) {
|
||||
|
@ -191,7 +220,7 @@ public class RunScriptOptions {
|
|||
*
|
||||
* @return value
|
||||
*/
|
||||
public Credentials getOverrideCredentials() {
|
||||
public Credentials getOverridingCredentials() {
|
||||
return overridingCredentials;
|
||||
}
|
||||
|
||||
|
@ -229,9 +258,19 @@ public class RunScriptOptions {
|
|||
return options.nameTask(name);
|
||||
}
|
||||
|
||||
public static RunScriptOptions overrideLoginUserWith(String user) {
|
||||
RunScriptOptions options = new RunScriptOptions();
|
||||
return options.overrideLoginUserWith(user);
|
||||
}
|
||||
|
||||
public static RunScriptOptions overrideLoginCredentialWith(String credential) {
|
||||
RunScriptOptions options = new RunScriptOptions();
|
||||
return options.overrideLoginCredentialWith(credential);
|
||||
}
|
||||
|
||||
public static RunScriptOptions overrideCredentialsWith(Credentials credentials) {
|
||||
RunScriptOptions options = new RunScriptOptions();
|
||||
return options.withOverridingCredentials(credentials);
|
||||
return options.overrideCredentialsWith(credentials);
|
||||
}
|
||||
|
||||
public static RunScriptOptions runAsRoot(boolean value) {
|
||||
|
@ -259,8 +298,8 @@ public class RunScriptOptions {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[overridingCredentials=" + (overridingCredentials != null) + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", runAsRoot=" + runAsRoot + ", blockOnComplete=" + blockOnComplete + ", wrapInInitScript=" + wrapInInitScript
|
||||
+ "]";
|
||||
+ ", runAsRoot=" + runAsRoot + ", blockOnComplete=" + blockOnComplete + ", wrapInInitScript="
|
||||
+ wrapInInitScript + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,13 +49,88 @@ import com.google.common.base.Throwables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TemplateOptions extends RunScriptOptions {
|
||||
public class TemplateOptions extends RunScriptOptions implements Cloneable {
|
||||
|
||||
@Override
|
||||
public TemplateOptions clone() {
|
||||
TemplateOptions options = new TemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
public void copyTo(TemplateOptions to) {
|
||||
if (!Arrays.equals(to.getInboundPorts(), this.getInboundPorts()))
|
||||
to.inboundPorts(this.getInboundPorts());
|
||||
if (this.getRunScript() != null)
|
||||
to.runScript(this.getRunScript());
|
||||
if (this.getPrivateKey() != null)
|
||||
to.installPrivateKey(this.getPrivateKey());
|
||||
if (this.getPublicKey() != null)
|
||||
to.authorizePublicKey(this.getPublicKey());
|
||||
if (this.getPort() != -1)
|
||||
to.blockOnPort(this.getPort(), this.getSeconds());
|
||||
if (this.isIncludeMetadata())
|
||||
to.withMetadata();
|
||||
if (!this.shouldBlockUntilRunning())
|
||||
to.blockUntilRunning(false);
|
||||
if (!this.shouldBlockOnComplete())
|
||||
to.blockOnComplete(false);
|
||||
if (this.getOverridingCredentials() != null)
|
||||
to.overrideCredentialsWith(this.getOverridingCredentials());
|
||||
if (this.getTaskName() != null)
|
||||
to.nameTask(this.getTaskName());
|
||||
}
|
||||
|
||||
public static final TemplateOptions NONE = new ImmutableTemplateOptions(new TemplateOptions());
|
||||
|
||||
public static class ImmutableTemplateOptions extends TemplateOptions {
|
||||
private final TemplateOptions delegate;
|
||||
|
||||
@Override
|
||||
public TemplateOptions clone() {
|
||||
return delegate.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskName() {
|
||||
return delegate.getTaskName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return delegate.getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeconds() {
|
||||
return delegate.getSeconds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Credentials getOverridingCredentials() {
|
||||
return delegate.getOverridingCredentials();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRunAsRoot() {
|
||||
return delegate.shouldRunAsRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBlockOnComplete() {
|
||||
return delegate.shouldBlockOnComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldWrapInInitScript() {
|
||||
return delegate.shouldWrapInInitScript();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
delegate.copyTo(to);
|
||||
}
|
||||
|
||||
public ImmutableTemplateOptions(TemplateOptions delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
@ -65,6 +140,72 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
return delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions runScript(Payload script) {
|
||||
throw new IllegalArgumentException("script is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions runScript(Statement script) {
|
||||
throw new IllegalArgumentException("script is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions installPrivateKey(Payload privateKey) {
|
||||
throw new IllegalArgumentException("privateKey is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions dontAuthorizePublicKey() {
|
||||
throw new IllegalArgumentException("public key is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public TemplateOptions authorizePublicKey(Payload publicKey) {
|
||||
throw new IllegalArgumentException("public key is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions blockOnPort(int port, int seconds) {
|
||||
throw new IllegalArgumentException("ports are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions nameTask(String name) {
|
||||
throw new IllegalArgumentException("task name is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions runAsRoot(boolean runAsRoot) {
|
||||
throw new IllegalArgumentException("runAsRoot is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
throw new IllegalArgumentException("credentials are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions overrideLoginUserWith(String loginUser) {
|
||||
throw new IllegalArgumentException("credentials are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions overrideLoginCredentialWith(String loginCredential) {
|
||||
throw new IllegalArgumentException("credentials are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions wrapInInitScript(boolean wrapInInitScript) {
|
||||
throw new IllegalArgumentException("wrapInInitScript is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions blockOnComplete(boolean blockOnComplete) {
|
||||
throw new IllegalArgumentException("blockOnComplete is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends TemplateOptions> T as(Class<T> clazz) {
|
||||
return delegate.as(clazz);
|
||||
|
@ -72,7 +213,7 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
|
||||
@Override
|
||||
public TemplateOptions authorizePublicKey(String publicKey) {
|
||||
throw new IllegalArgumentException("authorizePublicKey is immutable");
|
||||
throw new IllegalArgumentException("publicKey is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +248,7 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
|
||||
@Override
|
||||
public TemplateOptions inboundPorts(int... ports) {
|
||||
throw new IllegalArgumentException("ports is immutable");
|
||||
throw new IllegalArgumentException("ports are immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,12 +263,12 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
|
||||
@Override
|
||||
public TemplateOptions runScript(byte[] script) {
|
||||
throw new IllegalArgumentException("withMetadata is immutable");
|
||||
throw new IllegalArgumentException("script is immutable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions withMetadata() {
|
||||
throw new IllegalArgumentException("withMetadata is immutable");
|
||||
throw new IllegalArgumentException("metadata is immutable");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -210,7 +351,7 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
*/
|
||||
public TemplateOptions installPrivateKey(String privateKey) {
|
||||
checkArgument(checkNotNull(privateKey, "privateKey").startsWith("-----BEGIN RSA PRIVATE KEY-----"),
|
||||
"key should start with -----BEGIN RSA PRIVATE KEY-----");
|
||||
"key should start with -----BEGIN RSA PRIVATE KEY-----");
|
||||
this.privateKey = privateKey;
|
||||
return this;
|
||||
}
|
||||
|
@ -285,9 +426,19 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
return options.nameTask(name);
|
||||
}
|
||||
|
||||
public static TemplateOptions overrideLoginUserWith(String user) {
|
||||
TemplateOptions options = new TemplateOptions();
|
||||
return options.overrideLoginUserWith(user);
|
||||
}
|
||||
|
||||
public static TemplateOptions overrideLoginCredentialWith(String credential) {
|
||||
TemplateOptions options = new TemplateOptions();
|
||||
return options.overrideLoginCredentialWith(credential);
|
||||
}
|
||||
|
||||
public static TemplateOptions overrideCredentialsWith(Credentials credentials) {
|
||||
TemplateOptions options = new TemplateOptions();
|
||||
return options.withOverridingCredentials(credentials);
|
||||
return options.overrideCredentialsWith(credentials);
|
||||
}
|
||||
|
||||
public static TemplateOptions runAsRoot(boolean value) {
|
||||
|
@ -406,9 +557,9 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[inboundPorts=" + Arrays.toString(inboundPorts) + ", privateKey=" + (privateKey != null) + ", publicKey="
|
||||
+ (publicKey != null) + ", runScript=" + (script != null) + ", blockUntilRunning=" + blockUntilRunning
|
||||
+ ", blockOnComplete=" + blockOnComplete + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", metadata/details: " + includeMetadata + "]";
|
||||
+ (publicKey != null) + ", runScript=" + (script != null) + ", blockUntilRunning=" + blockUntilRunning
|
||||
+ ", blockOnComplete=" + blockOnComplete + ", port:seconds=" + port + ":" + seconds
|
||||
+ ", metadata/details: " + includeMetadata + "]";
|
||||
}
|
||||
|
||||
public TemplateOptions blockUntilRunning(boolean blockUntilRunning) {
|
||||
|
@ -486,8 +637,23 @@ public class TemplateOptions extends RunScriptOptions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||
return TemplateOptions.class.cast(super.withOverridingCredentials(overridingCredentials));
|
||||
public TemplateOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
return TemplateOptions.class.cast(super.overrideCredentialsWith(overridingCredentials));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions overrideLoginUserWith(String loginUser) {
|
||||
return TemplateOptions.class.cast(super.overrideLoginUserWith(loginUser));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions overrideLoginCredentialWith(String loginCredential) {
|
||||
return TemplateOptions.class.cast(super.overrideLoginCredentialWith(loginCredential));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateOptions wrapInInitScript(boolean wrapInInitScript) {
|
||||
return TemplateOptions.class.cast(super.wrapInInitScript(wrapInInitScript));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,22 +51,4 @@ public class AWSEC2TemplateBuilderImpl extends EC2TemplateBuilderImpl {
|
|||
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, imageMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
|
||||
super.copyTemplateOptions(from, to);
|
||||
if (from instanceof AWSEC2TemplateOptions) {
|
||||
AWSEC2TemplateOptions eFrom = AWSEC2TemplateOptions.class.cast(from);
|
||||
AWSEC2TemplateOptions eTo = AWSEC2TemplateOptions.class.cast(to);
|
||||
|
||||
if (eFrom.getSubnetId() != null)
|
||||
eTo.subnetId(eFrom.getSubnetId());
|
||||
if (eFrom.isMonitoringEnabled())
|
||||
eTo.enableMonitoring();
|
||||
if (!eFrom.shouldAutomaticallyCreatePlacementGroup())
|
||||
eTo.noPlacementGroup();
|
||||
if (eFrom.getPlacementGroup() != null)
|
||||
eTo.placementGroup(eFrom.getPlacementGroup());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,29 @@ import org.jclouds.util.Preconditions2;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
||||
public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneable {
|
||||
@Override
|
||||
public AWSEC2TemplateOptions clone() {
|
||||
AWSEC2TemplateOptions options = new AWSEC2TemplateOptions();
|
||||
copyTo(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyTo(TemplateOptions to) {
|
||||
super.copyTo(to);
|
||||
if (to instanceof AWSEC2TemplateOptions) {
|
||||
AWSEC2TemplateOptions eTo = AWSEC2TemplateOptions.class.cast(to);
|
||||
if (getSubnetId() != null)
|
||||
eTo.subnetId(getSubnetId());
|
||||
if (isMonitoringEnabled())
|
||||
eTo.enableMonitoring();
|
||||
if (!shouldAutomaticallyCreatePlacementGroup())
|
||||
eTo.noPlacementGroup();
|
||||
if (getPlacementGroup() != null)
|
||||
eTo.placementGroup(getPlacementGroup());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean monitoringEnabled;
|
||||
private String placementGroup = null;
|
||||
|
@ -114,7 +136,7 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
* @see EC2TemplateOptions#mapEBSSnapshotToDeviceName
|
||||
*/
|
||||
public static AWSEC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId,
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
@Nullable Integer sizeInGib, boolean deleteOnTermination) {
|
||||
AWSEC2TemplateOptions options = new AWSEC2TemplateOptions();
|
||||
return options.mapEBSSnapshotToDeviceName(deviceName, snapshotId, sizeInGib, deleteOnTermination);
|
||||
}
|
||||
|
@ -123,7 +145,7 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
* @see EC2TemplateOptions#mapNewVolumeToDeviceName
|
||||
*/
|
||||
public static AWSEC2TemplateOptions mapNewVolumeToDeviceName(String deviceName, int sizeInGib,
|
||||
boolean deleteOnTermination) {
|
||||
boolean deleteOnTermination) {
|
||||
AWSEC2TemplateOptions options = new AWSEC2TemplateOptions();
|
||||
return options.mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination);
|
||||
}
|
||||
|
@ -290,9 +312,9 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
|
||||
@Override
|
||||
public AWSEC2TemplateOptions mapEBSSnapshotToDeviceName(String deviceName, String snapshotId, Integer sizeInGib,
|
||||
boolean deleteOnTermination) {
|
||||
boolean deleteOnTermination) {
|
||||
return AWSEC2TemplateOptions.class.cast(super.mapEBSSnapshotToDeviceName(deviceName, snapshotId, sizeInGib,
|
||||
deleteOnTermination));
|
||||
deleteOnTermination));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,7 +331,7 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
@Override
|
||||
public AWSEC2TemplateOptions mapNewVolumeToDeviceName(String deviceName, int sizeInGib, boolean deleteOnTermination) {
|
||||
return AWSEC2TemplateOptions.class.cast(super
|
||||
.mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination));
|
||||
.mapNewVolumeToDeviceName(deviceName, sizeInGib, deleteOnTermination));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,8 +493,8 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public AWSEC2TemplateOptions withOverridingCredentials(Credentials overridingCredentials) {
|
||||
return AWSEC2TemplateOptions.class.cast(super.withOverridingCredentials(overridingCredentials));
|
||||
public AWSEC2TemplateOptions overrideCredentialsWith(Credentials overridingCredentials) {
|
||||
return AWSEC2TemplateOptions.class.cast(super.overrideCredentialsWith(overridingCredentials));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -544,9 +566,9 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions {
|
|||
public String toString() {
|
||||
|
||||
return "[groupIds=" + getGroupIds() + ", keyPair=" + getKeyPair() + ", noKeyPair="
|
||||
+ !shouldAutomaticallyCreateKeyPair() + ", monitoringEnabled=" + monitoringEnabled + ", placementGroup="
|
||||
+ placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", subnetId=" + subnetId + ", userData="
|
||||
+ Arrays.toString(getUserData()) + ", blockDeviceMappings=" + getBlockDeviceMappings() + "]";
|
||||
+ !shouldAutomaticallyCreateKeyPair() + ", monitoringEnabled=" + monitoringEnabled + ", placementGroup="
|
||||
+ placementGroup + ", noPlacementGroup=" + noPlacementGroup + ", subnetId=" + subnetId + ", userData="
|
||||
+ Arrays.toString(getUserData()) + ", blockDeviceMappings=" + getBlockDeviceMappings() + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue