Skip to content

Commit

Permalink
Merge pull request #540 from diarraa/openstack
Browse files Browse the repository at this point in the history
Openstack : Make the volume name reconfigurable and verify the floating IP association
  • Loading branch information
vincent-zurczak committed Jan 8, 2016
2 parents c116e99 + 0842b8f commit 814f164
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ public class OpenstackIaasHandler extends AbstractThreadedTargetHandler {

static final String FLOATING_IP_POOL = "openstack.floating-ip-pool";
static final String NETWORK_ID = "openstack.network-id";
//static final String VOLUME_ID = "openstack.volumeId";
static final String USE_BLOCK_STORAGE = "openstack.use-block-storage";
static final String DEFAULT_USE_BLOCK_STORAGE = "false";
static final String VOLUME_MOUNT_POINT = "openstack.volume-mount-point";
static final String DEFAULT_VOLUME_MOUNT_POINT = "/dev/vdb";
static final String VOLUME_NAME = "openstack.volume-name";
static final String DEFAULT_VOLUME_NAME = "roboconf-volume";
static final String VOLUME_SIZE_GB = "openstack.volume-size";
static final String DEFAULT_VOLUME_SIZE_GB = "5";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ public boolean configure() throws TargetException {
if( associateFloatingIp())
this.state = State.CREATE_VOLUME;

// if( state == State.ASSOCIATE_NETWORK )
// associateNetwork();

if( this.state == State.CREATE_VOLUME ) {
if( createBlockStorage())
this.state = State.ATTACH_VOLUME;
Expand Down Expand Up @@ -156,12 +153,8 @@ private boolean checkVmIsOnline() {
private boolean associateFloatingIp() {

// Associating a floating IP requires a client-side synchronization
// since Openstack does
// not provide it. Indeed, it can associate a floating IP to a new
// server, even if this
// address was already associated with another one. It is not possible,
// at the moment, to
// reserve a floating IP. So, we must treat this step with locks.
// since Openstack does not provide it. Indeed, it can associate a floating IP to a new
// server, even if this address was already associated with another one.
String floatingIpPool = this.targetProperties.get(OpenstackIaasHandler.FLOATING_IP_POOL);
if (Utils.isEmptyOrWhitespaces(floatingIpPool))
return true;
Expand All @@ -180,8 +173,8 @@ private boolean associateFloatingIp() {
String availableIp = null;
String anyZoneName = this.novaApi.getConfiguredZones().iterator().next();
FloatingIPApi floatingIPApi = this.novaApi.getFloatingIPExtensionForZone(anyZoneName).get();
for (FloatingIP ip : floatingIPApi.list().toList()) {
if (ip.getInstanceId() == null) {
for(FloatingIP ip : floatingIPApi.list().toList()) {
if (ip.getFixedIp() == null) {
availableIp = ip.getIp();
break;
}
Expand All @@ -202,38 +195,21 @@ private boolean associateFloatingIp() {
return done;
}

// /**
// * Associates a Neutron network with the VM (if necessary and if
// possible).
// * @throws TargetException
// */192.168.0.6
// private void associateNetwork() throws TargetException {
//
// String networkId = this.targetProperties.get(
// OpenstackIaasHandler.NETWORK_ID );
// if( ! Utils.isEmptyOrWhitespaces( networkId )) {
// NeutronApi neutronApi = OpenstackIaasHandler.neutronApi(
// this.targetProperties );
// Network network = neutronApi.getNetworkApi( this.anyZoneName ).get(
// networkId );
//
// }
// }

/**
* Creates a block storage in Openstack infrastructure.
* @throws TargetException
*/
public boolean createBlockStorage() throws TargetException {

String useBlockStorage = Utils.getValue(this.targetProperties, OpenstackIaasHandler.USE_BLOCK_STORAGE, "false");
String useBlockStorage = Utils.getValue(this.targetProperties, OpenstackIaasHandler.USE_BLOCK_STORAGE, OpenstackIaasHandler.DEFAULT_USE_BLOCK_STORAGE);
boolean isCreated = true;
if( Boolean.parseBoolean(useBlockStorage)) {
String vol = Utils.getValue(this.targetProperties, OpenstackIaasHandler.VOLUME_SIZE_GB, OpenstackIaasHandler.DEFAULT_VOLUME_SIZE_GB);
String name = Utils.getValue(this.targetProperties, OpenstackIaasHandler.VOLUME_NAME, OpenstackIaasHandler.DEFAULT_VOLUME_NAME);
int vsize = Integer.parseInt(vol);
String anyZoneName = this.novaApi.getConfiguredZones().iterator().next();
VolumeApi volumeApi = this.novaApi.getVolumeExtensionForZone(anyZoneName).get();
this.volumeId = volumeApi.create(vsize, CreateVolumeOptions.Builder.name("toto")).getId();
this.volumeId = volumeApi.create(vsize, CreateVolumeOptions.Builder.name(name)).getId();
isCreated = !Utils.isEmptyOrWhitespaces( this.volumeId );
if( !isCreated )
throw new TargetException( "No volume created" );
Expand Down

0 comments on commit 814f164

Please sign in to comment.