Skip to content

Commit 79e9bac

Browse files
Fix NPE during VM IP fetch for shared networks
1 parent 86827f8 commit 79e9bac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ public void setKubernetesServiceHelpers(final List<KubernetesServiceHelper> kube
672672
"Wait Interval (in seconds) for shared network vm dhcp ip addr fetch for next iteration ", true);
673673

674674
private static final ConfigKey<Integer> VmIpFetchTrialMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmip.max.retry", "10",
675-
"The max number of retrieval times for shared entwork vm dhcp ip fetch, in case of failures", true);
675+
"The max number of retrieval times for shared network vm dhcp ip fetch, in case of failures", true);
676676

677677
private static final ConfigKey<Integer> VmIpFetchThreadPoolMax = new ConfigKey<Integer>("Advanced", Integer.class, "externaldhcp.vmipFetch.threadPool.max", "10",
678678
"number of threads for fetching vms ip address", true);
@@ -2706,7 +2706,7 @@ protected void runInContext() {
27062706

27072707
if (vmIdAndCount.getRetrievalCount() <= 0) {
27082708
vmIdCountMap.remove(nicId);
2709-
logger.debug("Vm " + vmId +" nic "+nicId + " count is zero .. removing vm nic from map ");
2709+
logger.debug("Vm {} nic {} count is zero .. removing vm nic from map ", vmId, nicId);
27102710

27112711
ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM,
27122712
Domain.ROOT_DOMAIN, EventTypes.EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH,
@@ -2715,12 +2715,15 @@ protected void runInContext() {
27152715
continue;
27162716
}
27172717

2718-
27192718
UserVm userVm = _vmDao.findById(vmId);
27202719
VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId);
27212720
NicVO nicVo = _nicDao.findById(nicId);
2722-
NetworkVO network = _networkDao.findById(nicVo.getNetworkId());
2721+
if (ObjectUtils.anyNull(userVm, vmInstance, nicVo)) {
2722+
logger.warn("Couldn't fetch ip addr, Vm {} or nic {} doesn't exists", vmId, nicId);
2723+
continue;
2724+
}
27232725

2726+
NetworkVO network = _networkDao.findById(nicVo.getNetworkId());
27242727
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(userVm);
27252728
VirtualMachine vm = vmProfile.getVirtualMachine();
27262729
boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");

0 commit comments

Comments
 (0)