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;
}
Aggregations