use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class XenServerStorageMotionStrategy method getNonDestroyedSnapshots.
private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) {
List<SnapshotVO> lstSnapshots = snapshotDao.listByVolumeId(csVolumeId);
if (lstSnapshots == null) {
lstSnapshots = new ArrayList<>();
}
List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
for (SnapshotVO snapshot : lstSnapshots) {
if (!Snapshot.State.Destroyed.equals(snapshot.getState())) {
lstSnapshots2.add(snapshot);
}
}
return lstSnapshots2;
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class XenServerStorageMotionStrategy method verifyNoSnapshotsOnManagedStorageVolumes.
private void verifyNoSnapshotsOnManagedStorageVolumes(Map<VolumeInfo, DataStore> volumeToPool) {
for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
VolumeInfo volumeInfo = entry.getKey();
StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
if (storagePool.isManaged()) {
List<SnapshotVO> snapshots = getNonDestroyedSnapshots(volumeInfo.getId());
if (snapshots != null && snapshots.size() > 0) {
throw new CloudRuntimeException("Cannot perform this action on a volume with one or more snapshots");
}
}
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method deleteSnapshot.
/**
* Deletes snapshot on Datera
* @param snapshotInfo snapshot information
* @param storagePoolId primary storage
* @throws UnsupportedEncodingException
* @throws DateraObject.DateraError
*/
private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) throws UnsupportedEncodingException, DateraObject.DateraError {
long csSnapshotId = snapshotInfo.getId();
try {
DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePoolId, _storagePoolDetailsDao);
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
// Native snapshot being used, delete that
String snapshotName = snapshotDetails.getValue();
DateraUtil.deleteVolumeSnapshot(conn, snapshotName);
// check if the underlying volume needs to be deleted
SnapshotVO snapshot = _snapshotDao.findById(csSnapshotId);
VolumeVO volume = _volumeDao.findById(snapshot.getVolumeId());
if (volume == null) {
// deleted from Cloudstack. Check if other snapshots are using this volume
volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
if (shouldDeleteVolume(snapshot.getVolumeId(), snapshot.getId())) {
DateraUtil.deleteAppInstance(conn, volume.getFolder());
}
}
} else {
// An App Instance is being used to support the CloudStack volume snapshot.
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
String appInstanceName = snapshotDetails.getValue();
DateraUtil.deleteAppInstance(conn, appInstanceName);
}
snapshotDetailsDao.removeDetails(csSnapshotId);
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
// getUsedBytes(StoragePool) will not include the snapshot to delete because it
// has already been deleted by this point
long usedBytes = getUsedBytes(storagePool);
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePoolDao.update(storagePoolId, storagePool);
} catch (Exception ex) {
s_logger.debug("Error in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, ex);
throw ex;
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method createResourceFromSnapshot.
private String createResourceFromSnapshot(long csSnapshotId, String rscName, StoragePoolVO storagePoolVO) {
final String rscGrp = storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ? storagePoolVO.getUserInfo() : "DfltRscGrp";
final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
SnapshotVO snapshotVO = _snapshotDao.findById(csSnapshotId);
String snapName = LinstorUtil.RSC_PREFIX + snapshotVO.getUuid();
VolumeVO volumeVO = _volumeDao.findById(snapshotVO.getVolumeId());
String cloneRes = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
try {
s_logger.debug("Create new resource definition: " + rscName);
ResourceDefinitionCreate rdCreate = new ResourceDefinitionCreate();
ResourceDefinition rd = new ResourceDefinition();
rd.setName(rscName);
rd.setResourceGroupName(rscGrp);
rdCreate.setResourceDefinition(rd);
ApiCallRcList answers = linstorApi.resourceDefinitionCreate(rdCreate);
checkLinstorAnswersThrow(answers);
SnapshotRestore snapshotRestore = new SnapshotRestore();
snapshotRestore.toResource(rscName);
s_logger.debug("Create new volume definition for snapshot: " + cloneRes + ":" + snapName);
answers = linstorApi.resourceSnapshotsRestoreVolumeDefinition(cloneRes, snapName, snapshotRestore);
checkLinstorAnswersThrow(answers);
// restore snapshot to new resource
s_logger.debug("Restore resource from snapshot: " + cloneRes + ":" + snapName);
answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore);
checkLinstorAnswersThrow(answers);
return getDeviceName(linstorApi, rscName);
} catch (ApiException apiEx) {
s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
}
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method getNonDestroyedSnapshots.
private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) {
List<SnapshotVO> lstSnapshots = _snapshotDao.listByVolumeId(csVolumeId);
if (lstSnapshots == null) {
lstSnapshots = new ArrayList<>();
}
List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
for (SnapshotVO snapshot : lstSnapshots) {
if (!Snapshot.State.Destroyed.equals(snapshot.getState())) {
lstSnapshots2.add(snapshot);
}
}
return lstSnapshots2;
}
Aggregations