Search in sources :

Example 1 with OpenStackVolume

use of com.att.cdp.openstack.model.OpenStackVolume in project AJSC by att.

the class OpenStackVolumeService method getVolumes.

/**
 * Returns a list of volumes that match the supplied name
 *
 * @param name
 *            The name pattern of the volumes to be located. The name is a regular expression that is suitable for
 *            use in the Java String.matches() method.
 * @return A list (potentially empty) of all volumes that match the specified name pattern
 * @throws ZoneException
 *             - If the volume service cannot be accessed.
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.VolumeService#getVolumes(java.lang.String)
 */
@Override
public List<Volume> getVolumes(String name) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, name);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Volume> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Volumes volumes = nova.getClient().volumes().list(true).execute();
        for (com.woorea.openstack.nova.model.Volume volume : volumes) {
            if (name != null) {
                if (volume.getName() != null && volume.getName().matches(name)) {
                    list.add(new OpenStackVolume(context, volume));
                }
            } else {
                list.add(new OpenStackVolume(context, volume));
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) Volume(com.att.cdp.zones.model.Volume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) AbstractVolume(com.att.cdp.zones.spi.AbstractVolume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 2 with OpenStackVolume

use of com.att.cdp.openstack.model.OpenStackVolume in project AJSC by att.

the class OpenStackVolumeService method createVolume.

/**
 * This method is used to create a new volume using the Volume object (disconnected) as the model. When the method
 * returns, a connected model object is returned that should be used for any model navigation desired.
 *
 * @param template
 *            The template of the volume to create. This must contain at least a name and size. Other information
 *            will be supplied if not present. Any ID is ignored, and the ID of the created volume is returned in
 *            the connected volume object returned to the caller.
 * @return A Volume object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the volume cannot be created for some reason.
 * @see com.att.cdp.zones.VolumeService#createVolume(com.att.cdp.zones.model.Volume)
 */
@SuppressWarnings("nls")
@Override
public Volume createVolume(Volume template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, template.getName());
    RequestState.put(RequestState.SIZE, template.getSize());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.VolumeForCreate newVolume = new com.woorea.openstack.nova.model.VolumeForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("snapshotId", "snapshotId");
        dictionary.put("availabilityZone", "availabilityZone");
        ObjectMapper.map(template, newVolume, dictionary);
        OpenStackVolume volume = new OpenStackVolume(context, nova.getClient().volumes().create(newVolume).execute());
        return volume;
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) HashMap(java.util.HashMap) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 3 with OpenStackVolume

use of com.att.cdp.openstack.model.OpenStackVolume in project AJSC by att.

the class OpenStackVolumeService method getVolume.

/**
 * Returns information about the volume with the indicated id, if it exists.
 *
 * @param id
 *            The id of the volume that we want to find information about
 * @return The volume if it exists
 * @throws ZoneException
 *             - If the volume cannot be listed, or the volume does not exist
 * @see com.att.cdp.zones.VolumeService#getVolume(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Volume getVolume(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.Volume volume = nova.getClient().volumes().show(id).execute();
        if (volume == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Volume", id, context.getProvider().getName()));
        }
        return new OpenStackVolume(context, volume);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 4 with OpenStackVolume

use of com.att.cdp.openstack.model.OpenStackVolume in project AJSC by att.

the class OpenStackVolumeService method getVolume.

/**
 * Returns information about the volume with the indicated id, if it exists.
 *
 * @param id
 *            The id of the volume that we want to find information about
 * @return The volume if it exists
 * @throws ZoneException
 *             - If the volume cannot be listed, or the volume does not exist
 * @see com.att.cdp.zones.VolumeService#getVolume(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Volume getVolume(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, id);
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    try {
        com.woorea.openstack.cinder.model.Volume volume = cinder.getClient().volumes().show(id).execute();
        if (volume == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Volume", id, context.getProvider().getName()));
        }
        return new OpenStackVolume(context, volume);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 5 with OpenStackVolume

use of com.att.cdp.openstack.model.OpenStackVolume in project AJSC by att.

the class OpenStackVolumeService method getVolumes.

/**
 * Retrieves the list of volumes defined for this service.
 *
 * @return The list of volumes for this tenant, if any. The list may be empty if there are no volumes defined.
 * @see com.att.cdp.zones.VolumeService#getVolumes()
 */
@Override
public List<Volume> getVolumes() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    ArrayList<Volume> list = new ArrayList<>();
    try {
        com.woorea.openstack.cinder.model.Volumes volumes = cinder.getClient().volumes().list(true).execute();
        for (com.woorea.openstack.cinder.model.Volume volume : volumes) {
            list.add(new OpenStackVolume(context, volume));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) Volume(com.att.cdp.zones.model.Volume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) AbstractVolume(com.att.cdp.zones.spi.AbstractVolume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Aggregations

OpenStackContext (com.att.cdp.openstack.OpenStackContext)8 OpenStackVolume (com.att.cdp.openstack.model.OpenStackVolume)8 Context (com.att.cdp.zones.Context)8 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)8 Volume (com.att.cdp.zones.model.Volume)4 AbstractVolume (com.att.cdp.zones.spi.AbstractVolume)4 ArrayList (java.util.ArrayList)4 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)2 HashMap (java.util.HashMap)2