Search in sources :

Example 1 with Servers

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

the class OpenStackComputeService method getServers.

/**
 * Obtain a list of servers from the compute service.
 *
 * @return The list of servers that are defined.
 * @throws ZoneException
 *             - If any of the following conditions are true:
 *             <ul>
 *             <li>the user has not successfully logged in to the provider</li>
 *             <li>the context has been closed and this service is requested</li>
 *             <li>the current user does not have the rights to perform this operation</li>
 *             <li>the user and/or credentials are not valid</li>
 *             </ul>
 * @see com.att.cdp.zones.ComputeService#getServers()
 */
@Override
public List<Server> getServers() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Server> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Servers servers = nova.getClient().servers().list(true).execute();
        for (com.woorea.openstack.nova.model.Server s : servers.getList()) {
            list.add(new OpenStackServer(context, s));
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ArrayList(java.util.ArrayList) Servers(com.woorea.openstack.nova.model.Servers)

Example 2 with Servers

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

the class OpenStackComputeService method getServers.

/**
 * Returns the list of servers that match the name pattern supplied.
 *
 * @param name
 *            A regular expression that can be used to filter server names. A string that is suitable to use in the
 *            Java <code>String.matches()</code> method.
 * @return The server
 * @throws ZoneException
 *             If the host cannot be found
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.ComputeService#getServers(java.lang.String)
 */
@Override
public List<Server> getServers(String name) throws ZoneException {
    // checkArg(name, "name");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    RequestState.put(RequestState.SERVER, name);
    ArrayList<Server> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Servers servers = nova.getClient().servers().list(true).execute();
        for (com.woorea.openstack.nova.model.Server s : servers.getList()) {
            if (name != null) {
                if (s.getName().matches(name)) {
                    list.add(new OpenStackServer(context, s));
                }
            } else {
                list.add(new OpenStackServer(context, s));
            }
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ArrayList(java.util.ArrayList) Servers(com.woorea.openstack.nova.model.Servers)

Example 3 with Servers

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

the class OpenStackComputeService method findAllServersUsingKey.

/**
 * @see com.att.cdp.zones.ComputeService#findAllServersUsingKey(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public List<String> findAllServersUsingKey(String keyPair) throws ZoneException {
    checkArg(keyPair, "keyPair");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    RequestState.put(RequestState.KEYPAIR, keyPair);
    List<String> users = new ArrayList<String>();
    try {
        Servers servers = nova.getClient().servers().list(false).execute();
        for (com.woorea.openstack.nova.model.Server server : servers.getList()) {
            if (keyPair.equals(server.getKeyName())) {
                users.add(server.getId());
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return users;
}
Also used : OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList) Servers(com.woorea.openstack.nova.model.Servers)

Example 4 with Servers

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

the class OpenStackComputeService method getServers.

/**
 * Returns the list of servers that match the name pattern supplied.
 *
 * @param name
 *            A regular expression that can be used to filter server names.
 *            A string that is suitable to use in the Java
 *            <code>String.matches()</code> method.
 * @return The server
 * @throws ZoneException
 *             If the host cannot be found
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.ComputeService#getServers(java.lang.String)
 */
@Override
public List<Server> getServers(String name) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    RequestState.put(RequestState.SERVER, name);
    ArrayList<Server> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Servers servers = nova.getClient().servers().list(true).execute();
        for (com.woorea.openstack.nova.model.Server s : servers.getList()) {
            if (name != null) {
                if (s.getName().matches(name)) {
                    list.add(new OpenStackServer(context, s));
                }
            } else {
                list.add(new OpenStackServer(context, s));
            }
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ArrayList(java.util.ArrayList) Servers(com.woorea.openstack.nova.model.Servers)

Example 5 with Servers

use of com.woorea.openstack.nova.model.Servers 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)

Aggregations

Servers (com.woorea.openstack.nova.model.Servers)7 ArrayList (java.util.ArrayList)7 OpenStackContext (com.att.cdp.openstack.OpenStackContext)6 Context (com.att.cdp.zones.Context)6 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)6 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)4 Server (com.att.cdp.zones.model.Server)4 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)4 Nova (com.woorea.openstack.nova.Nova)1 FloatingIp (com.woorea.openstack.nova.model.FloatingIp)1 FloatingIps (com.woorea.openstack.nova.model.FloatingIps)1 Addresses (com.woorea.openstack.nova.model.Server.Addresses)1 Address (com.woorea.openstack.nova.model.Server.Addresses.Address)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1