houthuis commented on a change in pull request #2793: Destroyvm also removes
volumes
URL: https://github.com/apache/cloudstack/pull/2793#discussion_r219527693
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2751,27 +2749,55 @@ public UserVm destroyVm(DestroyVMCmd cmd) throws
ResourceUnavailableException, C
// check if VM exists
UserVmVO vm = _vmDao.findById(vmId);
- if (vm == null) {
+ if (vm == null || vm.getRemoved() != null) {
throw new InvalidParameterValueException("unable to find a virtual
machine with id " + vmId);
}
+ if (vm.getState() == State.Destroyed || vm.getState() ==
State.Expunging) {
+ s_logger.trace("Vm id=" + vmId + " is already destroyed");
+ return vm;
+ }
+
// check if there are active volume snapshots tasks
s_logger.debug("Checking if there are any ongoing snapshots on the
ROOT volumes associated with VM with ID " + vmId);
if (checkStatusOfVolumeSnapshots(vmId, Volume.Type.ROOT)) {
throw new CloudRuntimeException("There is/are unbacked up
snapshot(s) on ROOT volume, vm destroy is not permitted, please try again
later.");
}
s_logger.debug("Found no ongoing snapshots on volume of type ROOT, for
the vm with id " + vmId);
+ List<VolumeVO> volumes = getVolumesFromIds(cmd);
+
+ checkForUnattachedVolumes(vmId, volumes);
+ validateVolumes(volumes);
+ detachVolumesFromVm(volumes);
Review comment:
@wido this change has been made. please give the PR another review
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services