@@ -5430,19 +5430,37 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
54305430
54315431 @Override
54325432 public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) {
5433- if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
5433+ if (nic == null) {
5434+ logger.warn("Skipping PVLAN setup on host {} because NIC profile is null", hostId);
5435+ return false;
5436+ }
5437+
5438+ if (nic.getBroadCastUri() == null) {
5439+ logger.debug("Skipping PVLAN setup on host {} for NIC {} because broadcast URI is null", hostId, nic);
5440+ return false;
5441+ }
5442+
5443+ String scheme = nic.getBroadCastUri().getScheme();
5444+ if (!"pvlan".equalsIgnoreCase(scheme)) {
5445+ logger.debug("Skipping PVLAN setup on host {} for NIC {} because broadcast URI scheme is {}", hostId, nic, scheme);
54345446 return false;
54355447 }
54365448 String op = "add";
54375449 if (!add) {
54385450 // "delete" would remove all the rules(if using ovs) related to this vm
54395451 op = "delete";
54405452 }
5441- Network network = _networkDao.findById(nic.getNetworkId());
5453+
54425454 Host host = _hostDao.findById(hostId);
5455+ if (host == null) {
5456+ logger.warn("Host with id {} does not exist", hostId);
5457+ return false;
5458+ }
5459+
5460+ Network network = _networkDao.findById(nic.getNetworkId());
54435461 String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
54445462 PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
5445- Answer answer = null ;
5463+ Answer answer;
54465464 try {
54475465 answer = _agentMgr.send(hostId, cmd);
54485466 } catch (OperationTimedoutException e) {
0 commit comments