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();
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.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.
the class OpenStackComputeService method getAttachments.
/**
* Returns a map of the volume attachments for the specified server. The key of the map is the device name for the
* volume attachment. This is the device identification which the server will "see".
*
* @param id
* The server ID for which we wish to obtain all attachments (if any).
* @return A map of the volume attachments, or an empty map if there are none. The map is keyed by the device name
* used to attach the volume. The value of the entry is the ID of the volume attached at that device.
* @throws ZoneException
* - If the attachments cannot be obtained
* @see com.att.cdp.zones.ComputeService#getAttachments(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public Map<String, String> getAttachments(String id) throws ZoneException {
checkArg(id, "id");
connect();
trackRequest();
RequestState.put(RequestState.SERVER, id);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
HashMap<String, String> map = new HashMap<>();
try {
for (VolumeAttachment attachment : nova.getClient().servers().listVolumeAttachments(id).execute()) {
RequestState.put(RequestState.VOLUME, attachment.getVolumeId());
if (attachment.getDevice() != null) {
RequestState.put(RequestState.DEVICE, attachment.getDevice());
map.put(attachment.getDevice(), attachment.getVolumeId());
} else {
System.err.println("No device found for " + attachment);
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
} catch (Exception e) {
throw new ZoneException("Error obtaining volume attachments.", e);
}
return map;
}
use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.
the class OpenStackComputeService method getAccessControlList.
/**
* @see com.att.cdp.zones.ComputeService#getAccessControlList(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public ACL getAccessControlList(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 {
SecurityGroup group = nova.getClient().securityGroups().showSecurityGroup(id).execute();
return new OpenStackACL(context, group);
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
return null;
}
use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.
the class OpenStackComputeService method getVirtualInterfaces.
/**
* This method returns a list of OS Virtual Interfaces for a specified server instance.
* <p>
* This includes the ID for the virtual interface as well as the associated mac address.
* </p>
*
* @return A list of virtual interfaces
* @throws ZoneException
* If the virtual interfaces cannot be listed
* @see com.att.cdp.zones.ComputeService#getVirtualInterfaces(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public List<VirtualInterface> getVirtualInterfaces(String id) throws ZoneException {
checkArg(id, "id");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
ArrayList<VirtualInterface> list = new ArrayList<>();
try {
com.woorea.openstack.nova.model.VirtualInterfaces virtualInterfaces = nova.getClient().servers().listVirtualInterfaces(id).execute();
for (com.woorea.openstack.nova.model.VirtualInterface vi : virtualInterfaces.getList()) {
VirtualInterface virtualInterface = new OpenStackVirtualInterface(context, vi);
list.add(virtualInterface);
}
} catch (OpenStackBaseException e) {
ExceptionMapper.mapException(e);
}
return list;
}
use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.
the class OpenStackComputeService method addACLRule.
/**
* @see com.att.cdp.zones.ComputeService#addACLRule(java.lang.String, com.att.cdp.zones.model.Rule)
*/
@SuppressWarnings("nls")
@Override
public Rule addACLRule(String aclId, Rule rule) throws ZoneException {
checkArg(aclId, "aclId");
checkArg(rule, "rule");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
SecurityGroup group = nova.getClient().securityGroups().showSecurityGroup(aclId).execute();
if (group != null) {
com.woorea.openstack.nova.model.SecurityGroup.Rule createdRule = nova.getClient().securityGroups().createSecurityGroupRule(aclId, rule.getProtocol().toString(), rule.getFromPort(), rule.getToPort(), rule.getSourceIpRange()).execute();
return new OpenStackRule(context, createdRule);
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
return null;
}
Aggregations