Search in sources :

Example 46 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackComputeService method deleteAccessControlList.

/**
 * @see com.att.cdp.zones.ComputeService#deleteAccessControlList(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void deleteAccessControlList(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        nova.getClient().securityGroups().deleteSecurityGroup(id).execute();
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 47 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackComputeService method getServer.

/**
 * Returns the indicated host using the specified identification token
 *
 * @param id
 *            The identification of the server
 * @return The server
 * @throws ZoneException
 *             - If the host cannot be found
 * @see com.att.cdp.zones.ComputeService#getServer(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Server getServer(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.Server s = nova.getClient().servers().show(id).execute();
        return new OpenStackServer(context, s);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer)

Example 48 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException 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 49 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackComputeService method deleteServer.

/**
 * Delete the specified server using it's id.
 *
 * @param serverId
 *            The server to be deleted.
 * @throws ZoneException
 *             If the server does not exist or cannot be deleted for some
 *             reason.
 * @see com.att.cdp.zones.ComputeService#deleteServer(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void deleteServer(String serverId) throws ZoneException {
    checkArg(serverId, "serverId");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, serverId);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        Server server = getServer(serverId);
        Server.Status status = server.getStatus();
        RequestState.put(RequestState.STATUS, status.toString());
        if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY) || status.equals(Server.Status.ERROR)) {
            List<Port> ports = server.getPorts();
            for (Port port : ports) {
                port.delete();
            }
            nova.getClient().servers().delete(serverId).execute();
        } else {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString(), Server.Status.ERROR.toString()))));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
}
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) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort)

Example 50 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackComputeService method detachVolume.

/**
 * Detaches the volume from the specified server.
 *
 * @param server
 *            The server to be manipulated
 * @param deviceName
 *            The device to be detached
 * @throws ZoneException
 *             If the volume cannot be detached for some reason
 * @see com.att.cdp.zones.ComputeService#detachVolume(com.att.cdp.zones.model.Server,
 *      java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void detachVolume(Server server, String deviceName) throws ZoneException {
    checkArg(server, "server");
    checkArg(deviceName, "deviceName");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, server.getName());
    RequestState.put(RequestState.DEVICE, deviceName);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    server.refreshStatus();
    Server.Status status = server.getStatus();
    RequestState.put(RequestState.STATUS, status.toString());
    if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY)) {
        try {
            Map<String, String> attachments = getAttachments(server);
            for (Map.Entry<String, String> entry : attachments.entrySet()) {
                if (entry.getKey().equals(deviceName)) {
                    nova.getClient().servers().detachVolume(server.getId(), entry.getValue()).execute();
                }
                break;
            }
        } catch (OpenStackBaseException ex) {
            ExceptionMapper.mapException(ex);
        }
    } else {
        throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId().toString(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString()))));
    }
}
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) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)151 OpenStackContext (com.att.cdp.openstack.OpenStackContext)140 Context (com.att.cdp.zones.Context)140 ArrayList (java.util.ArrayList)54 Quantum (com.woorea.openstack.quantum.Quantum)36 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 ZoneException (com.att.cdp.exceptions.ZoneException)15 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)14 Server (com.att.cdp.zones.model.Server)11 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)11 HashMap (java.util.HashMap)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10 Snapshot (com.att.cdp.zones.model.Snapshot)10 OpenStackACL (com.att.cdp.openstack.model.OpenStackACL)8 OpenStackImage (com.att.cdp.openstack.model.OpenStackImage)8 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)8 OpenStackVolume (com.att.cdp.openstack.model.OpenStackVolume)8 OpenStackNetwork (com.att.cdp.openstack.model.OpenStackNetwork)7 Network (com.att.cdp.zones.model.Network)7 Port (com.att.cdp.zones.model.Port)7