Skip to content

Commit 908f594

Browse files
authored
configDrive: Fix failure to delete (unstarted) VM (#6146)
* configDrive: Fix failure to delete (unstarted)VM * Address comments * Address comments
1 parent bcd1a32 commit 908f594

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ private Long findAgentId(VirtualMachineProfile profile, DeployDestination dest,
497497
agentId = dest.getHost().getId();
498498
}
499499
if (!VirtualMachineManager.VmConfigDriveOnPrimaryPool.valueIn(dest.getDataCenter().getId()) &&
500-
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId())) {
500+
!VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId()) && dataStore != null) {
501501
agentId = findAgentIdForImageStore(dataStore);
502502
}
503503
return agentId;
@@ -630,6 +630,10 @@ private DataStore getDatastoreForConfigDriveIso(DiskTO disk, VirtualMachineProfi
630630
private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUnavailableException {
631631
Long hostId = (vm.getHostId() != null) ? vm.getHostId() : vm.getLastHostId();
632632
Location location = getConfigDriveLocation(vm.getId());
633+
if (hostId == null) {
634+
LOG.info(String.format("The VM was never booted; no config-drive ISO created for VM %s", vm.getName()));
635+
return true;
636+
}
633637
if (location == Location.HOST) {
634638
return deleteConfigDriveIsoOnHostCache(vm, hostId);
635639
}
@@ -639,7 +643,9 @@ private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUna
639643

640644
if (location == Location.SECONDARY) {
641645
dataStore = _dataStoreMgr.getImageStoreWithFreeCapacity(vm.getDataCenterId());
642-
agentId = findAgentIdForImageStore(dataStore);
646+
if (dataStore != null) {
647+
agentId = findAgentIdForImageStore(dataStore);
648+
}
643649
} else if (location == Location.PRIMARY) {
644650
List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
645651
if (volumes != null && volumes.size() > 0) {

0 commit comments

Comments
 (0)