use of com.linbit.linstor.api.model.Snapshot in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method takeSnapshot.
@Override
public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) {
s_logger.debug("Linstor: takeSnapshot with snapshot: " + snapshotInfo.getUuid());
final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
long storagePoolId = volumeVO.getPoolId();
final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
final DevelopersApi api = LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
final String rscName = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
Snapshot snapshot = new Snapshot();
snapshot.setName(getSnapshotName(snapshotInfo.getUuid()));
CreateCmdResult result;
try {
ApiCallRcList answers = api.resourceSnapshotCreate(rscName, snapshot);
if (answers.hasError()) {
final String errMsg = answers.get(0).getMessage();
s_logger.error("Snapshot error: " + errMsg);
result = new CreateCmdResult(null, new Answer(null, false, errMsg));
result.setResult(errMsg);
} else {
s_logger.info(String.format("Successfully took snapshot from %s", rscName));
SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO) snapshotInfo.getTO();
snapshotObjectTo.setPath(rscName + "-" + snapshotInfo.getName());
result = new CreateCmdResult(null, new CreateObjectAnswer(snapshotObjectTo));
result.setResult(null);
}
} catch (ApiException apiExc) {
s_logger.error(apiExc);
result = new CreateCmdResult(null, new Answer(null, false, apiExc.getBestMessage()));
result.setResult(apiExc.getBestMessage());
}
callback.complete(result);
}
Aggregations