use of com.woorea.openstack.nova.Nova in project AJSC by att.
the class OpenStackNetworkService method assignIpAddressFromPool.
/**
* @see com.att.cdp.zones.NetworkService#assignIpAddressFromPool(java.lang.String, java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public String assignIpAddressFromPool(String serverId, String pool) throws ZoneException {
checkArg(serverId, "serverId");
checkArg(pool, "pool");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVER, serverId);
RequestState.put(RequestState.POOL, pool);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, novaConnector.getEndpoint());
Nova client = novaConnector.getClient();
FloatingIpsExtension extension = client.floatingIps();
if (extension == null) {
throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_UNSUPPORTED_OPERATION, "getAvailableAddresses", context.getProvider().getName()));
}
try {
String ip = reserveFreeFloatingIPAddress(pool);
if (ip != null) {
assignIpAddress(serverId, ip);
return ip;
}
} catch (OpenStackBaseException e) {
ExceptionMapper.mapException(e);
}
throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_UNAVAILABLE, "Floating IP Address", context.getProvider().getName()));
}
use of com.woorea.openstack.nova.Nova in project AJSC by att.
the class TestNovaConnector method testGlanceConnector.
@Test
@Ignore
public void testGlanceConnector() throws ZoneException {
OpenStackContext context = login();
NovaConnector connector = context.getNovaConnector();
assertNotNull(connector);
Access access = connector.getAccess();
assertNotNull(access);
Nova client = connector.getClient();
assertNotNull(client);
logout(context);
}
use of com.woorea.openstack.nova.Nova in project AJSC by att.
the class OpenStackNetworkService method reserveFreeFloatingIPAddress.
/**
* This method is used o determine which IP addresses in the floating ip address pool specified are free, and to
* reserve the first one
*
* @param pool
* The name of the pool to be searched, or null if we are searching all pools available to the tenant
* @return The reserved IP address (or null if there are none available in the pool)
* @throws OpenStackResponseException
* @throws OpenStackConnectException
*/
@SuppressWarnings("nls")
private String reserveFreeFloatingIPAddress(String pool) throws OpenStackConnectException, OpenStackResponseException {
Nova client = novaConnector.getClient();
HashSet<String> available = new HashSet<>();
Context context = getContext();
FloatingIps ips = client.floatingIps().list().execute();
for (FloatingIp ip : ips.getList()) {
if (pool == null || pool.equalsIgnoreCase(ip.getPool())) {
available.add(ip.getIp());
}
}
Servers servers = client.servers().list(true).execute();
for (com.woorea.openstack.nova.model.Server server : servers.getList()) {
Addresses allocatedAddresses = server.getAddresses();
Map<String, List<Address>> addressMap = allocatedAddresses.getAddresses();
for (Map.Entry<String, List<Address>> entry : addressMap.entrySet()) {
List<Address> addressList = entry.getValue();
for (Address address : addressList) {
if (address.getType().equalsIgnoreCase("floating")) {
available.remove(address.getAddr());
}
}
}
}
if (!available.isEmpty()) {
Iterator<String> it = available.iterator();
while (it.hasNext()) {
String ip = it.next();
if (((OpenStackContext) context).allocateFloatingIP(ip)) {
return ip;
}
}
}
return null;
}
Aggregations