mirror of https://github.com/apache/cloudstack.git
server: detach data disks before destroying vms (#5356)
This commit is contained in:
parent
442f89cfdb
commit
e968f3b16a
|
|
@ -2985,7 +2985,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
|
||||
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) {
|
||||
|
|
@ -2994,7 +2996,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
}
|
||||
|
||||
deleteVolumesFromVm(volumesToBeDeleted);
|
||||
deleteVolumesFromVm(volumesToBeDeleted, expunge);
|
||||
|
||||
return destroyedVm;
|
||||
}
|
||||
|
|
@ -7322,13 +7324,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7353,13 +7355,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue