use of org.openstack4j.model.compute.Address in project airavata by apache.
the class OpenstackIntfImpl method deleteServer.
@Override
public void deleteServer(String serverId) {
try {
Server server = this.getServer(serverId);
// Get Floating IP if there is one associated.
String floatingIpAddr = null;
for (Address novaAddress : server.getAddresses().getAddresses().get(properties.getProperty(Constants.OS_NETWORK_NAME))) {
novaAddress = (NovaAddress) novaAddress;
if (novaAddress.getType().equals(IPType.FLOATING.toString())) {
floatingIpAddr = novaAddress.getAddr();
break;
}
}
if (server != null) {
os.compute().servers().delete(serverId);
// Deallocating Floating IP.
if (floatingIpAddr != null) {
for (FloatingIP floatIp : os.compute().floatingIps().list()) {
if (floatIp.getFloatingIpAddress().equals(floatingIpAddr)) {
os.compute().floatingIps().deallocateIP(floatIp.getId());
}
}
}
logger.info("Server deleted successfully for ID: " + serverId);
}
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to delete server with ID: " + serverId);
}
}
use of org.openstack4j.model.compute.Address in project cloudbreak by hortonworks.
the class ComputeApiExtractor method extractMetadata.
@Override
public CloudInstanceMetaData extractMetadata(OSClient<?> client, Server server, String instanceId) {
String hypervisor = hypervisorExtractor.getHypervisor(server);
String privateIp = null;
String floatingIp = null;
Map<String, List<? extends Address>> adrMap = server.getAddresses().getAddresses();
LOGGER.debug("Address map: {} of instance: {}", adrMap, server.getName());
for (Entry<String, List<? extends Address>> entry : adrMap.entrySet()) {
LOGGER.debug("Network resource key: {} of instance: {}", entry.getKey(), server.getName());
for (Address adr : entry.getValue()) {
LOGGER.debug("Network resource key: {} of instance: {}, address: {}", entry.getKey(), server.getName(), adr);
switch(adr.getType()) {
case "fixed":
privateIp = adr.getAddr();
LOGGER.info("PrivateIp of instance: {} is {}", server.getName(), privateIp);
break;
case "floating":
floatingIp = adr.getAddr();
LOGGER.info("FloatingIp of instance: {} is {}", server.getName(), floatingIp);
break;
default:
LOGGER.error("No such network resource type: {}, instance: {}", adr.getType(), server.getName());
}
}
}
return new CloudInstanceMetaData(privateIp, floatingIp, hypervisor);
}
Aggregations