configDrive: Fix failure to delete (unstarted) VM (#137)

This commit is contained in:
Pearl Dsilva 2022-03-31 07:06:09 +05:30 committed by GitHub
parent 79fc6ca4d9
commit 2bd5a5daa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -497,7 +497,7 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle
agentId = dest.getHost().getId();
}
if (!VirtualMachineManager.VmConfigDriveOnPrimaryPool.valueIn(dest.getDataCenter().getId()) &&
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId())) {
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId()) && dataStore != null) {
agentId = findAgentIdForImageStore(dataStore);
}
return agentId;
@ -629,6 +629,10 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle
private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUnavailableException {
Long hostId = (vm.getHostId() != null) ? vm.getHostId() : vm.getLastHostId();
if (hostId == null) {
LOG.info(String.format("The VM was never booted; no config-drive ISO created for VM %s", vm.getName()));
return true;
}
Location location = getConfigDriveLocation(vm.getId());
if (location == Location.HOST) {
return deleteConfigDriveIsoOnHostCache(vm, hostId);
@ -639,7 +643,9 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle
if (location == Location.SECONDARY) {
dataStore = _dataStoreMgr.getImageStoreWithFreeCapacity(vm.getDataCenterId());
agentId = findAgentIdForImageStore(dataStore);
if (dataStore != null) {
agentId = findAgentIdForImageStore(dataStore);
}
} else if (location == Location.PRIMARY) {
List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
if (volumes != null && volumes.size() > 0) {