Search in sources :

Example 1 with Address

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);
    }
}
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)

Example 2 with Address

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);
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) Address(org.openstack4j.model.compute.Address) List(java.util.List)

Aggregations

Address (org.openstack4j.model.compute.Address)2 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)1 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1 FloatingIP (org.openstack4j.model.compute.FloatingIP)1 Server (org.openstack4j.model.compute.Server)1 NovaAddress (org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress)1