use of org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress 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);
}
}
Aggregations