Search in sources :

Example 16 with Server

use of com.att.cdp.zones.model.Server 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();
    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().toString(), 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 : 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 17 with Server

use of com.att.cdp.zones.model.Server 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();
        if (servers != null && servers.getList() != null) {
            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 18 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class OpenStackComputeService method attachVolume.

/**
 * Attach a volume to a specified server. The volume is then attached to the
 * server for it to use when the server is started.
 *
 * @param server
 *            The server we are manipulating
 * @param volume
 *            The volume we wish to attach to the server
 * @param deviceName
 *            the name of the device presented to the server
 * @throws ZoneException
 *             If the volume cannot be attached for some reason
 * @see com.att.cdp.zones.ComputeService#attachVolume(com.att.cdp.zones.model.Server,
 *      com.att.cdp.zones.model.Volume, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void attachVolume(Server server, Volume volume, String deviceName) throws ZoneException {
    checkArg(server, "server");
    checkArg(volume, "volume");
    checkArg(deviceName, "deviceName");
    if (!checkDeviceName(deviceName)) {
        throw new InvalidRequestException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_DEVICE_NAME, deviceName));
    }
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, server);
    RequestState.put(RequestState.VOLUME, volume.getId());
    RequestState.put(RequestState.DEVICE, volume.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    /*
		 * Get the list of existing attachments and check to see if the device
		 * name is already used
		 */
    Map<String, String> attachments = getAttachments(server);
    if (attachments.containsKey(deviceName)) {
        throw new InvalidRequestException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_DEVICE_NAME, deviceName));
    }
    /*
		 * Check the server status to see if it is correct for attempting the
		 * attachment
		 */
    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 {
            nova.getClient().servers().attachVolume(server.getId(), volume.getId(), deviceName).execute();
        } 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(), EELFResourceManager.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) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException)

Example 19 with Server

use of com.att.cdp.zones.model.Server 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 volume
 *            The volume 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,
 *      com.att.cdp.zones.model.Volume)
 */
@SuppressWarnings("nls")
@Override
public void detachVolume(Server server, Volume volume) throws ZoneException {
    checkArg(server, "server");
    checkArg(volume, "volume");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVER, server.getName());
    RequestState.put(RequestState.VOLUME, volume.getName());
    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 {
            nova.getClient().servers().detachVolume(server.getId(), volume.getId()).execute();
        } catch (OpenStackBaseException ex) {
            ExceptionMapper.mapException(ex);
        }
    } 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()))));
    }
}
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)

Example 20 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class TestComputeService method testListPorts.

/**
 * Test that we can list all ports on some server
 *
 * @throws ZoneException
 *             if anything fails
 */
@Test
@Ignore
public void testListPorts() throws ZoneException {
    Context context = connect();
    ComputeService service = context.getComputeService();
    List<Server> servers = service.getServers();
    assertNotNull(servers);
    assertFalse(servers.isEmpty());
    for (Server server : servers) {
        List<Port> ports = service.getPorts(server);
        assertNotNull(ports);
        assertFalse(ports.isEmpty());
        List<Port> serverPorts = server.getPorts();
        assertNotNull(serverPorts);
        assertFalse(serverPorts.isEmpty());
        assertTrue(ports.containsAll(serverPorts));
    // System.out.printf("Server %s has %d ports\n", server.getName(),
    // ports.size());
    }
}
Also used : Context(com.att.cdp.zones.Context) Server(com.att.cdp.zones.model.Server) Port(com.att.cdp.zones.model.Port) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Server (com.att.cdp.zones.model.Server)26 Context (com.att.cdp.zones.Context)22 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)17 OpenStackContext (com.att.cdp.openstack.OpenStackContext)16 Ignore (org.junit.Ignore)13 ComputeService (com.att.cdp.zones.ComputeService)12 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)12 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)11 Test (org.junit.Test)11 ZoneException (com.att.cdp.exceptions.ZoneException)9 ArrayList (java.util.ArrayList)7 Port (com.att.cdp.zones.model.Port)6 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)4 NetworkService (com.att.cdp.zones.NetworkService)4 Network (com.att.cdp.zones.model.Network)4 Servers (com.woorea.openstack.nova.model.Servers)4 HashMap (java.util.HashMap)4 ACL (com.att.cdp.zones.model.ACL)3 Subnet (com.att.cdp.zones.model.Subnet)3 List (java.util.List)3