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