Search in sources :

Example 1 with Addresses

use of com.woorea.openstack.nova.model.Server.Addresses in project AJSC by att.

the class OpenStackNetworkService method reserveFreeFloatingIPAddress.

/**
 * This method is used o determine which IP addresses in the floating ip address pool specified are free, and to
 * reserve the first one
 *
 * @param pool
 *            The name of the pool to be searched, or null if we are searching all pools available to the tenant
 * @return The reserved IP address (or null if there are none available in the pool)
 * @throws OpenStackResponseException
 * @throws OpenStackConnectException
 */
@SuppressWarnings("nls")
private String reserveFreeFloatingIPAddress(String pool) throws OpenStackConnectException, OpenStackResponseException {
    Nova client = novaConnector.getClient();
    HashSet<String> available = new HashSet<>();
    Context context = getContext();
    FloatingIps ips = client.floatingIps().list().execute();
    for (FloatingIp ip : ips.getList()) {
        if (pool == null || pool.equalsIgnoreCase(ip.getPool())) {
            available.add(ip.getIp());
        }
    }
    Servers servers = client.servers().list(true).execute();
    for (com.woorea.openstack.nova.model.Server server : servers.getList()) {
        Addresses allocatedAddresses = server.getAddresses();
        Map<String, List<Address>> addressMap = allocatedAddresses.getAddresses();
        for (Map.Entry<String, List<Address>> entry : addressMap.entrySet()) {
            List<Address> addressList = entry.getValue();
            for (Address address : addressList) {
                if (address.getType().equalsIgnoreCase("floating")) {
                    available.remove(address.getAddr());
                }
            }
        }
    }
    if (!available.isEmpty()) {
        Iterator<String> it = available.iterator();
        while (it.hasNext()) {
            String ip = it.next();
            if (((OpenStackContext) context).allocateFloatingIP(ip)) {
                return ip;
            }
        }
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Address(com.woorea.openstack.nova.model.Server.Addresses.Address) FloatingIps(com.woorea.openstack.nova.model.FloatingIps) Nova(com.woorea.openstack.nova.Nova) Servers(com.woorea.openstack.nova.model.Servers) FloatingIp(com.woorea.openstack.nova.model.FloatingIp) Addresses(com.woorea.openstack.nova.model.Server.Addresses) OpenStackContext(com.att.cdp.openstack.OpenStackContext) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with Addresses

use of com.woorea.openstack.nova.model.Server.Addresses in project AJSC by att.

the class TestOpenstackServerMapping method testMapJsonToServer.

@Test
public void testMapJsonToServer() throws JsonParseException, JsonMappingException, IOException {
    Server server = om.readValue(json, Server.class);
    assertNotNull(server);
    Server.Addresses addresses = server.getAddresses();
    assertNotNull(addresses);
    Map<String, List<Server.Addresses.Address>> map = addresses.getAddresses();
    assertNotNull(map);
    assertFalse(map.isEmpty());
    assertEquals(1, map.size());
    List<Server.Addresses.Address> list = map.get("VLAN_OVERLAY_422");
    assertNotNull(list);
    assertFalse(list.isEmpty());
    Server.Addresses.Address entry = list.get(0);
    assertNotNull(entry);
    assertEquals("135.144.122.121", entry.getAddr());
}
Also used : Addresses(com.woorea.openstack.nova.model.Server.Addresses) Addresses(com.woorea.openstack.nova.model.Server.Addresses) Server(com.woorea.openstack.nova.model.Server) List(java.util.List) Test(org.junit.Test)

Aggregations

Addresses (com.woorea.openstack.nova.model.Server.Addresses)2 List (java.util.List)2 OpenStackContext (com.att.cdp.openstack.OpenStackContext)1 Context (com.att.cdp.zones.Context)1 Nova (com.woorea.openstack.nova.Nova)1 FloatingIp (com.woorea.openstack.nova.model.FloatingIp)1 FloatingIps (com.woorea.openstack.nova.model.FloatingIps)1 Server (com.woorea.openstack.nova.model.Server)1 Address (com.woorea.openstack.nova.model.Server.Addresses.Address)1 Servers (com.woorea.openstack.nova.model.Servers)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Test (org.junit.Test)1