use of com.woorea.openstack.nova.api.extensions.FloatingIpsExtension 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.api.extensions.FloatingIpsExtension in project AJSC by att.
the class OpenStackNetworkService method getFloatingIpPools.
/**
* @see com.att.cdp.zones.NetworkService#getFloatingIpPools()
*/
@SuppressWarnings("nls")
@Override
public List<String> getFloatingIpPools() throws ZoneException {
HashSet<String> pools = new HashSet<>();
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, novaConnector.getEndpoint());
FloatingIpsExtension extension = novaConnector.getClient().floatingIps();
if (extension == null) {
throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_UNSUPPORTED_OPERATION, "getAvailableAddresses", context.getProvider().getName()));
}
try {
for (FloatingIp ip : extension.list().execute()) {
if (!pools.contains(ip.getPool())) {
pools.add(ip.getPool());
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
return Collections.list(Collections.enumeration(pools));
}
use of com.woorea.openstack.nova.api.extensions.FloatingIpsExtension in project AJSC by att.
the class OpenStackNetworkService method getAvailableAddresses.
/**
* This method allows the caller to obtain a list of the available IP addresses from the Floating IP address (DNS)
* pool.
*
* @return The list of available IP Addresses that can be used to assign a floating IP address to a server.
* @throws ZoneException
* If the service is not available or the pool cannot be obtained
* @see com.att.cdp.zones.NetworkService#getAvailableAddresses(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public List<String> getAvailableAddresses(String pool) throws ZoneException {
checkArg(pool, "pool");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.POOL, pool);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, novaConnector.getEndpoint());
ArrayList<String> addresses = new ArrayList<>();
FloatingIpsExtension extension = novaConnector.getClient().floatingIps();
if (extension == null) {
throw new NotSupportedException(EELFResourceManager.format(OSMsg.PAL_OS_UNSUPPORTED_OPERATION, "getAvailableAddresses", context.getProvider().getName()));
}
try {
FloatingIps ips = extension.list().execute();
for (FloatingIp ip : ips) {
if (ip.getPool().equalsIgnoreCase(pool)) {
String ipAddress = ip.getIp();
addresses.add(ipAddress);
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
return addresses;
}
Aggregations