Skip to content

Commit

Permalink
Update floating IP verification #97
Browse files Browse the repository at this point in the history
  • Loading branch information
diarraa committed Dec 8, 2015
1 parent ab5e684 commit 0842b8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +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 VOLUME_NAME_DEFAULT = "roboconf-volume";
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 @@ -30,8 +30,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

//import org.jclouds.openstack.neutron.v2.domain.FloatingIP;
//import org.jclouds.openstack.neutron.v2.extensions.FloatingIPApi;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
import org.jclouds.openstack.nova.v2_0.domain.Server;
Expand Down Expand Up @@ -74,7 +72,7 @@ public class OpenstackMachineConfigurator implements MachineConfigurator {
* @author Vincent Zurczak - Linagora
*/
public static enum State {
WAITING_VM, ASSOCIATE_FLOATING_IP, COMPLETE, ASSOCIATE_NETWORK, CREATE_VOLUME, ATTACH_VOLUME;
WAITING_VM, ASSOCIATE_FLOATING_IP, COMPLETE, CREATE_VOLUME, ATTACH_VOLUME;
}

private final Instance scopedInstance;
Expand All @@ -83,7 +81,6 @@ public static enum State {
private final Logger logger = Logger.getLogger(getClass().getName());
private String volumeId = "";
private NovaApi novaApi;
//private NeutronApi neutronApi;
private State state = State.WAITING_VM;

/**
Expand All @@ -107,9 +104,6 @@ public Instance getScopedInstance() {
public void close() throws IOException {
if( this.novaApi != null)
this.novaApi.close();

// if( this.neutronApi != null)
// this.neutronApi.close();
}

@Override
Expand All @@ -118,23 +112,13 @@ public boolean configure() throws TargetException {
if( this.novaApi == null )
this.novaApi = OpenstackIaasHandler.novaApi( this.targetProperties );

// if( this.neutronApi == null )
// this.neutronApi = OpenstackIaasHandler.neutronApi( this.targetProperties );

if( this.state == State.WAITING_VM )
if( checkVmIsOnline())
this.state = State.ASSOCIATE_FLOATING_IP;

if( this.state == State.ASSOCIATE_FLOATING_IP )
if( associateFloatingIp())
this.state = State.CREATE_VOLUME;
//this.state = State.ASSOCIATE_NETWORK;


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


if( this.state == State.CREATE_VOLUME ) {
if( createBlockStorage())
Expand Down Expand Up @@ -169,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 @@ -192,10 +172,7 @@ private boolean associateFloatingIp() {
// Find a floating IP
String availableIp = null;
String anyZoneName = this.novaApi.getConfiguredZones().iterator().next();
//String anyZoneName = this.neutronApi.getConfiguredRegions().iterator().next();
FloatingIPApi floatingIPApi = this.novaApi.getFloatingIPExtensionForZone(anyZoneName).get();
//FloatingIPApi floatingIPApi = this.neutronApi.getFloatingIPApi(anyZoneName).get();
//List<IterableWithMarker<FloatingIP>> floatingIps = floatingIPApi.list().toList();
for(FloatingIP ip : floatingIPApi.list().toList()) {
if (ip.getFixedIp() == null) {
availableIp = ip.getIp();
Expand All @@ -218,34 +195,17 @@ private boolean associateFloatingIp() {
return done;
}

// /**
// * Associates a Neutron network with the VM (if necessary and if possible).
// * @throws TargetException
// */
// private boolean associateNetwork() throws TargetException {
//
// String networkId = this.targetProperties.get( OpenstackIaasHandler.NETWORK_ID );
// String anyZoneName = this.novaApi.getConfiguredZones().iterator().next();
// boolean isAssociated = true;
// if( ! Utils.isEmptyOrWhitespaces( networkId )) {
// NeutronApi neutronApi = OpenstackIaasHandler.neutronApi( this.targetProperties );
// Network network = neutronApi.getNetworkApi( anyZoneName ).get( networkId );
// isAssociated = !Utils.isEmptyOrWhitespaces( network.getId());
// }
// return isAssociated;
// }

/**
* 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.VOLUME_NAME_DEFAULT);
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();
Expand Down

0 comments on commit 0842b8f

Please sign in to comment.