diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index 9a3808cc8..686af3a60 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -402,8 +402,17 @@ def vol_info(vol_meta, vol_size_info, datastore): # Return error, or None for OK def removeVMDK(vmdk_path): logging.info("*** removeVMDK: %s", vmdk_path) - cmd = "{0} {1}".format(VMDK_DELETE_CMD, vmdk_path) + # Check the current volume status + attached, uuid, attach_as = getStatusAttached(vmdk_path) + if attached: + vm = findVmByUuid(uuid) + logging.info("*** removeVMDK: %s is in use by %s VM uuid = %s", + vmdk_path, vm.config.name, uuid) + return err("Failed to remove volume {0}, is in use by VM {1}.".format( + vmdk_path, vm.config.name)) + + cmd = "{0} {1}".format(VMDK_DELETE_CMD, vmdk_path) # Workaround timing/locking issues. retry_count = 0 while True: