Search in sources :

Example 1 with VolumeAttachment

use of com.woorea.openstack.nova.model.VolumeAttachment 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;
}
Also used : VolumeAttachment(com.woorea.openstack.nova.model.VolumeAttachment) ZoneException(com.att.cdp.exceptions.ZoneException) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ContextClosedException(com.att.cdp.exceptions.ContextClosedException) NotLoggedInException(com.att.cdp.exceptions.NotLoggedInException)

Example 2 with VolumeAttachment

use of com.woorea.openstack.nova.model.VolumeAttachment 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();
    Context context = getContext();
    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;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) VolumeAttachment(com.woorea.openstack.nova.model.VolumeAttachment) ZoneException(com.att.cdp.exceptions.ZoneException) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ContextClosedException(com.att.cdp.exceptions.ContextClosedException) NotLoggedInException(com.att.cdp.exceptions.NotLoggedInException)

Aggregations

ContextClosedException (com.att.cdp.exceptions.ContextClosedException)2 InvalidRequestException (com.att.cdp.exceptions.InvalidRequestException)2 NotLoggedInException (com.att.cdp.exceptions.NotLoggedInException)2 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)2 ZoneException (com.att.cdp.exceptions.ZoneException)2 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)2 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)2 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)2 VolumeAttachment (com.woorea.openstack.nova.model.VolumeAttachment)2 HashMap (java.util.HashMap)2 OpenStackContext (com.att.cdp.openstack.OpenStackContext)1 Context (com.att.cdp.zones.Context)1