Fix for the issue of recover VM not able to attach the data disks which are there before destroy in case of VMware

This commit is contained in:
Harikrishna Patnala 2020-11-23 13:31:58 +05:30
parent aa67f9c6e2
commit 426e347a23
2 changed files with 8 additions and 7 deletions

View File

@ -38,6 +38,7 @@ import com.cloud.storage.dao.VMTemplateDetailsDao;
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 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
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 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
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());
}
}

View File

@ -2946,13 +2946,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
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) {