Search in sources :

Example 1 with NovaAddress

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);
    }
}
Also used : Server(org.openstack4j.model.compute.Server) Address(org.openstack4j.model.compute.Address) NovaAddress(org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress) FloatingIP(org.openstack4j.model.compute.FloatingIP) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 Address (org.openstack4j.model.compute.Address)1 FloatingIP (org.openstack4j.model.compute.FloatingIP)1 Server (org.openstack4j.model.compute.Server)1 NovaAddress (org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress)1