[JCLOUDS-1360] add support for block device mappings to Nova

This commit is contained in:
andreaturli 2017-11-18 09:08:54 +01:00
parent 9b59d099d1
commit ec03b710a7
2 changed files with 28 additions and 3 deletions

View File

@ -131,6 +131,7 @@ 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);

View File

@ -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<Network> novaNetworks;
protected String availabilityZone;
// TODO move up to TemplateOptions as SoftLayer also have something similar?
protected Set<BlockDeviceMapping> 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<BlockDeviceMapping> 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<BlockDeviceMapping> getBlockDeviceMappings() {
return blockDeviceMappings;
}
public static class Builder {
/**