Fix for the issue of recover VM not able to attach the data disks which are there before destroy in case of VMware
diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
index e4cb893..3e86cea 100644
--- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
+++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
@@ -38,6 +38,7 @@
import com.cloud.utils.StringUtils;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.UserVmDetailVO;
+import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VmDetailConstants;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.UserVmDetailsDao;
@@ -220,6 +221,8 @@
UserVmDetailsDao userVmDetailsDao;
@Inject
private SecondaryStorageVmDao secondaryStorageVmDao;
+ @Inject
+ VolumeApiService _volumeApiService;
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
protected List<StoragePoolAllocator> _storagePoolAllocators;
@@ -1038,6 +1041,10 @@
if (s_logger.isDebugEnabled()) {
s_logger.debug("Detaching " + vol);
}
+ VMInstanceVO vm = _userVmDao.findById(vmId);
+ if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
+ _volumeApiService.detachVolumeViaDestroyVM(vmId, vol.getId());
+ }
_volsDao.detachVolume(vol.getId());
}
}
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index 3d447c6..7877d54 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -2946,13 +2946,7 @@
stopVirtualMachine(vmId, VmDestroyForcestop.value());
- if (vm.getHypervisorType() == HypervisorType.VMware) {
- List<VolumeVO> allVolumes = _volsDao.findByInstance(vm.getId());
- allVolumes.removeIf(vol -> vol.getVolumeType() == Volume.Type.ROOT);
- detachVolumesFromVm(allVolumes);
- } else {
- detachVolumesFromVm(volumesToBeDeleted);
- }
+ detachVolumesFromVm(volumesToBeDeleted);
UserVm destroyedVm = destroyVm(vmId, expunge);
if (expunge) {