Search in sources :

Example 1 with SnapshotCreateRequest

use of com.emc.storageos.cinder.model.SnapshotCreateRequest in project coprhd-controller by CoprHD.

the class CinderApi method createSnapshot.

/**
 * Shows the specified volume attachment details.
 *
 * @param serverId the server id
 * @param volumeAttachmentId the volume attachment id
 * @return the volume attachment response
 */
/*
     * public VolumeAttachResponse showVolumeAttachment(String serverId, String volumeAttachmentId)
     * {
     * _log.info("CinderApi - start showVolumeAttachment");
     * String showVolumeAttachmentUri = endPoint.getBaseUri()
     * + String.format(CinderConstants.URI_LIST_VOLUME_ATTACHMENT,
     * new Object[] { endPoint.getCinderTenantId(), serverId, volumeAttachmentId });
     * ClientResponse js_response = get_client().get(URI.create(showVolumeAttachmentUri));
     * String jsonString = js_response.getEntity(String.class);
     * 
     * VolumeAttachResponse volumeAttachmentDetails = new Gson().fromJson(jsonString, VolumeAttachResponse.class);
     * _log.info("CinderApi - end showVolumeAttachment");
     * return volumeAttachmentDetails;
     * }
     */
/**
 * Create Snapshot operation ( It is asynchronous operation )
 *
 * @param volumeName
 * @param volumeTypeId
 * @return
 * @throws Exception
 */
public String createSnapshot(String volumeId, String snapshotName) throws Exception {
    _log.info("CinderApi - start createSnapshot");
    Gson gson = new Gson();
    VolumeShowResponse volumeDetails = showVolume(volumeId);
    String volumeName = volumeDetails.volume.name;
    SnapshotCreateRequest request = new SnapshotCreateRequest();
    request.snapshot.name = snapshotName;
    request.snapshot.description = "Snapshot of volume " + volumeName;
    request.snapshot.volume_id = volumeId;
    request.snapshot.force = true;
    String snapshotCreateUri = endPoint.getBaseUri() + String.format(CinderConstants.URI_CREATE_SNAPSHOT, endPoint.getCinderTenantId());
    _log.debug("Creating snapshot with uri : {}", snapshotCreateUri);
    String json = gson.toJson(request);
    _log.debug("Creating snapshot with body : {}", json);
    ClientResponse js_response = getClient().postWithHeader(URI.create(snapshotCreateUri), json);
    String s = js_response.getEntity(String.class);
    _log.debug("Got the response {}", s);
    _log.debug("Response status {}", String.valueOf(js_response.getStatus()));
    String snapshotId = "";
    if (js_response.getStatus() == ClientResponse.Status.ACCEPTED.getStatusCode()) {
        // This means snapshot creation request accepted
        SnapshotCreateResponse response = gson.fromJson(SecurityUtils.sanitizeJsonString(s), SnapshotCreateResponse.class);
        snapshotId = response.snapshot.id;
    } else {
        throw CinderException.exceptions.snapshotCreationFailed(s);
    }
    return snapshotId;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) SnapshotCreateRequest(com.emc.storageos.cinder.model.SnapshotCreateRequest) Gson(com.google.gson.Gson) VolumeShowResponse(com.emc.storageos.cinder.model.VolumeShowResponse)

Aggregations

SnapshotCreateRequest (com.emc.storageos.cinder.model.SnapshotCreateRequest)1 SnapshotCreateResponse (com.emc.storageos.cinder.model.SnapshotCreateResponse)1 VolumeShowResponse (com.emc.storageos.cinder.model.VolumeShowResponse)1 Gson (com.google.gson.Gson)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1