diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 49761905f004..efd42ef63af2 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -5405,7 +5405,19 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl @Override public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) { - if (!nic.getBroadCastUri().getScheme().equals("pvlan")) { + if (nic == null) { + logger.warn("Skipping PVLAN setup on host {} because NIC profile is null", hostId); + return false; + } + + if (nic.getBroadCastUri() == null) { + logger.debug("Skipping PVLAN setup on host {} for NIC {} because broadcast URI is null", hostId, nic); + return false; + } + + String scheme = nic.getBroadCastUri().getScheme(); + if (!"pvlan".equalsIgnoreCase(scheme)) { + logger.debug("Skipping PVLAN setup on host {} for NIC {} because broadcast URI scheme is {}", hostId, nic, scheme); return false; } String op = "add"; @@ -5413,11 +5425,17 @@ public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) { // "delete" would remove all the rules(if using ovs) related to this vm op = "delete"; } - Network network = _networkDao.findById(nic.getNetworkId()); + Host host = _hostDao.findById(hostId); + if (host == null) { + logger.warn("Host with id {} does not exist", hostId); + return false; + } + + Network network = _networkDao.findById(nic.getNetworkId()); String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network); PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress()); - Answer answer = null; + Answer answer; try { answer = _agentMgr.send(hostId, cmd); } catch (OperationTimedoutException e) {