Search in sources :

Example 11 with OpenStackSnapshot

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

the class OpenStackSnapshotService method getSnapshot.

/**
 * Returns information about the snapshot with the indicated id, if it exists.
 *
 * @param id
 *            The id of the snapshot that we want to find information about
 * @return The snapshot if it exists
 * @throws ZoneException
 *             - If the snapshot cannot be listed, or the snapshot does not exist
 * @see com.att.cdp.zones.SnapshotService#getSnapshot(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Snapshot getSnapshot(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.Snapshot snapshot = nova.getClient().snapshots().show(id).execute();
        if (snapshot == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Snapshot", id, context.getProvider().getName()));
        }
        return new OpenStackSnapshot(context, snapshot);
    } 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) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 12 with OpenStackSnapshot

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

the class OpenStackSnapshotService method createSnapshot.

/**
 * This method is used to create a new snapshot using the Snapshot 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 snapshot to create. This must contain at least a name and volumeId. Other
 *            information will be supplied if not present. Any ID is ignored, and the ID of the created snapshot is
 *            returned in the connected snapshot object returned to the caller.
 * @return A Snapshot object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the snapshot cannot be created for some reason.
 * @see com.att.cdp.zones.SnapshotService#createSnapshot(com.att.cdp.zones.model.Snapshot)
 */
@SuppressWarnings("nls")
@Override
public Snapshot createSnapshot(Snapshot template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, template.getName());
    RequestState.put(RequestState.VOLUME, template.getVolumeId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.SnapshotForCreate newSnapshot = new com.woorea.openstack.nova.model.SnapshotForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("volumeId", "volumeId");
        ObjectMapper.map(template, newSnapshot, dictionary);
        OpenStackSnapshot snapshot = new OpenStackSnapshot(context, nova.getClient().snapshots().create(newSnapshot).execute());
        return snapshot;
    } 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) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot)

Example 13 with OpenStackSnapshot

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

the class OpenStackSnapshotService method getSnapshots.

/**
 * Returns a list of snapshots that match the supplied name
 *
 * @param name
 *            The name pattern of the snapshots 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 snapshots that match the specified name pattern
 * @throws ZoneException
 *             - If the snapshot service cannot be accessed.
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.SnapshotService#getSnapshots(java.lang.String)
 */
@Override
public List<Snapshot> getSnapshots(String name) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, name);
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    ArrayList<Snapshot> list = new ArrayList<>();
    try {
        com.woorea.openstack.cinder.model.Snapshots snapshots = cinder.getClient().snapshots().list(true).execute();
        for (com.woorea.openstack.cinder.model.Snapshot snap : snapshots) {
            if (name != null) {
                if (snap.getName() != null && snap.getName().matches(name)) {
                    list.add(new OpenStackSnapshot(context, snap));
                }
            } else {
                list.add(new OpenStackSnapshot(context, snap));
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) Snapshot(com.att.cdp.zones.model.Snapshot) AbstractSnapshot(com.att.cdp.zones.spi.AbstractSnapshot) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 14 with OpenStackSnapshot

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

the class OpenStackSnapshotService method getSnapshots.

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

Example 15 with OpenStackSnapshot

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

the class OpenStackSnapshotService method getSnapshot.

/**
 * Returns information about the snapshot with the indicated id, if it exists.
 *
 * @param id
 *            The id of the snapshot that we want to find information about
 * @return The snapshot if it exists
 * @throws ZoneException
 *             - If the snapshot cannot be listed, or the snapshot does not exist
 * @see com.att.cdp.zones.SnapshotService#getSnapshot(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Snapshot getSnapshot(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, id);
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    try {
        com.woorea.openstack.cinder.model.Snapshot snapshot = cinder.getClient().snapshots().show(id).execute();
        if (snapshot == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Snapshot", id, context.getProvider().getName()));
        }
        return new OpenStackSnapshot(context, snapshot);
    } 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) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Aggregations

OpenStackContext (com.att.cdp.openstack.OpenStackContext)18 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 Context (com.att.cdp.zones.Context)18 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)18 Snapshot (com.att.cdp.zones.model.Snapshot)10 ArrayList (java.util.ArrayList)10 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)4 AbstractSnapshot (com.att.cdp.zones.spi.AbstractSnapshot)4 HashMap (java.util.HashMap)4