Skip to content

Commit a14aae8

Browse files
committed
add restriction on snapshot from vm snapshot creation
1 parent 2bc8403 commit a14aae8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

api/src/main/java/com/cloud/storage/VolumeApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Volume updateVolume(long volumeId, String path, String state, Long storageId,
137137

138138
void updateDisplay(Volume volume, Boolean displayVolume);
139139

140-
Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName) throws ResourceAllocationException;
140+
Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName, Long vmSnapshotId) throws ResourceAllocationException;
141141

142142
/**
143143
* Checks if the storage pool supports the disk offering tags.

api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public ApiCommandResourceType getApiResourceType() {
153153

154154
@Override
155155
public void create() throws ResourceAllocationException {
156-
Snapshot snapshot = this._volumeService.allocSnapshotForVm(getVmId(), getVolumeId(), getSnapshotName());
156+
Snapshot snapshot = this._volumeService.allocSnapshotForVm(getVmId(), getVolumeId(), getSnapshotName(), getVMSnapshotId());
157157
if (snapshot != null) {
158158
this.setEntityId(snapshot.getId());
159159
this.setEntityUuid(snapshot.getUuid());

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,7 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName,
40174017
}
40184018

40194019
@Override
4020-
public Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName) throws ResourceAllocationException {
4020+
public Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName, Long vmSnapshotId) throws ResourceAllocationException {
40214021
Account caller = CallContext.current().getCallingAccount();
40224022
VMInstanceVO vm = _vmInstanceDao.findById(vmId);
40234023
if (vm == null) {
@@ -4069,6 +4069,10 @@ public Snapshot allocSnapshotForVm(Long vmId, Long volumeId, String snapshotName
40694069
throw new InvalidParameterValueException("Cannot perform this operation, unsupported on storage pool type " + storagePool.getPoolType());
40704070
}
40714071

4072+
if (vmSnapshotDetailsDao.listDetails(vmSnapshotId).stream().anyMatch(vmSnapshotDetailsVO -> vmSnapshotDetailsVO.getName().equals(KVM_FILE_BASED_STORAGE_SNAPSHOT))) {
4073+
throw new InvalidParameterValueException("Cannot perform this operation, unsupported VM snapshot type.");
4074+
}
4075+
40724076
return snapshotMgr.allocSnapshot(volumeId, Snapshot.MANUAL_POLICY_ID, snapshotName, null, true, null);
40734077
}
40744078

0 commit comments

Comments
 (0)