Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions 16 server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,9 @@ public UserVm destroyVm(DestroyVMCmd cmd) throws ResourceUnavailableException, C

stopVirtualMachine(vmId, VmDestroyForcestop.value());

detachVolumesFromVm(volumesToBeDeleted);
// Detach all data disks from VM
List<VolumeVO> dataVols = _volsDao.findByInstanceAndType(vmId, Volume.Type.DATADISK);
detachVolumesFromVm(dataVols);

UserVm destroyedVm = destroyVm(vmId, expunge);
if (expunge) {
Expand All @@ -2994,7 +2996,7 @@ public UserVm destroyVm(DestroyVMCmd cmd) throws ResourceUnavailableException, C
}
}

deleteVolumesFromVm(volumesToBeDeleted);
deleteVolumesFromVm(volumesToBeDeleted, expunge);

return destroyedVm;
}
Expand Down Expand Up @@ -7322,13 +7324,13 @@ private void checkForUnattachedVolumes(long vmId, List<VolumeVO> volumes) {
StringBuilder sb = new StringBuilder();

for (VolumeVO volume : volumes) {
if (volume.getInstanceId() == null || vmId != volume.getInstanceId()) {
if (volume.getInstanceId() == null || vmId != volume.getInstanceId() || volume.getVolumeType() != Volume.Type.DATADISK) {
sb.append(volume.toString() + "; ");
}
}

if (!StringUtils.isEmpty(sb.toString())) {
throw new InvalidParameterValueException("The following supplied volumes are not attached to the VM: " + sb.toString());
throw new InvalidParameterValueException("The following supplied volumes are not DATADISK attached to the VM: " + sb.toString());
}
}

Expand All @@ -7353,13 +7355,13 @@ private void detachVolumesFromVm(List<VolumeVO> volumes) {
}
}

private void deleteVolumesFromVm(List<VolumeVO> volumes) {
private void deleteVolumesFromVm(List<VolumeVO> volumes, boolean expunge) {

for (VolumeVO volume : volumes) {

boolean deleteResult = _volumeService.deleteVolume(volume.getId(), CallContext.current().getCallingAccount());
Volume result = _volumeService.destroyVolume(volume.getId(), CallContext.current().getCallingAccount(), expunge, false);

if (!deleteResult) {
if (result == null) {
s_logger.error("DestroyVM remove volume - failed to delete volume " + volume.getInstanceId() + " from instance " + volume.getId());
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.