diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index 38e4232df7..02cfa2b079 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -131,7 +131,8 @@ public class NovaComputeServiceAdapter implements if (templateOptions.getKeyPairName() != null) { options.keyPairName(templateOptions.getKeyPairName()); } - + if (!templateOptions.getBlockDeviceMappings().isEmpty()) options.blockDeviceMappings(templateOptions.getBlockDeviceMappings()); + logger.debug(">> creating new server region(%s) name(%s) image(%s) flavor(%s) options(%s)", regionId, name, imageId, flavorId, options); final ServerCreated lightweightServer = novaApi.getServerApi(regionId).create(name, imageId, flavorId, options); if (!serverRunningPredicate.apply(RegionAndId.fromRegionAndId(regionId, lightweightServer.getId()))) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java index 51b6bb2e2b..992302eb77 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptions.java @@ -28,6 +28,7 @@ import java.util.Set; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.LoginCredentials; import org.jclouds.openstack.nova.v2_0.NovaApi; +import org.jclouds.openstack.nova.v2_0.domain.BlockDeviceMapping; import org.jclouds.openstack.nova.v2_0.domain.Network; import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.scriptbuilder.domain.Statement; @@ -91,6 +92,8 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { protected boolean configDrive; protected Set novaNetworks; protected String availabilityZone; + // TODO move up to TemplateOptions as SoftLayer also have something similar? + protected Set blockDeviceMappings = ImmutableSet.of(); @Override public boolean equals(Object o) { @@ -107,13 +110,14 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { && equal(this.diskConfig, that.diskConfig) && equal(this.configDrive, that.configDrive) && equal(this.novaNetworks, that.novaNetworks) - && equal(this.availabilityZone, that.availabilityZone); + && equal(this.availabilityZone, that.availabilityZone) + && equal(this.blockDeviceMappings, that.blockDeviceMappings); } @Override public int hashCode() { return Objects.hashCode(super.hashCode(), autoAssignFloatingIp, floatingIpPoolNames, generateKeyPair, keyPairName, - Arrays.hashCode(userData), diskConfig, configDrive, novaNetworks, availabilityZone); + Arrays.hashCode(userData), diskConfig, configDrive, novaNetworks, availabilityZone, blockDeviceMappings); } @Override @@ -131,6 +135,7 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { toString.add("configDrive", configDrive); toString.add("novaNetworks", novaNetworks); toString.add("availabilityZone", availabilityZone); + toString.add("blockDeviceMappings", blockDeviceMappings); return toString; } @@ -195,6 +200,21 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { return this; } + /** + * @see #getBlockDeviceMappings() + */ + public NovaTemplateOptions blockDeviceMappings(BlockDeviceMapping... blockDeviceMappings) { + return blockDeviceMappings(ImmutableSet.copyOf(checkNotNull(blockDeviceMappings, "blockDeviceMappings"))); + } + + /** + * @see #getBlockDeviceMappings() + */ + public NovaTemplateOptions blockDeviceMappings(Iterable blockDeviceMappings) { + this.blockDeviceMappings = ImmutableSet.copyOf(blockDeviceMappings); + return this; + } + /** * The floating IP pool name(s) to use when allocating a FloatingIP. Applicable * only if #shouldAutoAssignFloatingIp() returns true. If not set will attempt to @@ -259,6 +279,10 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { return availabilityZone; } + public Set getBlockDeviceMappings() { + return blockDeviceMappings; + } + public static class Builder { /**