houthuis commented on a change in pull request #2793: Destroyvm also removes 
volumes
URL: https://github.com/apache/cloudstack/pull/2793#discussion_r209562028
 
 

 ##########
 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:
   We don't stop the VM for a regular detach cmd? This has been tested on KVM 
(with a small and large amount of volumes) and it worked fine. I'm happy to 
make the change if required though

----------------------------------------------------------------
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

Reply via email to