diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java index 3198a03ba7c..44282fe83e6 100755 --- a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java +++ b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java @@ -209,7 +209,6 @@ public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceSta dns = nic.getDns2(); } DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName(), dns, nic.getGateway()); - dhcpCommand.setDefaultRouter(_nicDao.findDefaultNicForVM(profile.getVirtualMachine().getId()).getGateway()); String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()); //prepareBareMetalDhcpEntry(nic, dhcpCommand); diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 64ed84e7099..bb5d7cf6f61 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -2023,8 +2023,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (sendDnsDhcpData) { DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName()); - - dhcpCommand.setDefaultRouter(_nicDao.findDefaultNicForVM(profile.getVirtualMachine().getId()).getGateway()); + + String defaultDhcpIp = findDefaultDhcpIp(profile.getVirtualMachine().getId()); + dhcpCommand.setDefaultRouter(defaultDhcpIp); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, routerControlIpAddress); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, router.getGuestIpAddress()); @@ -2083,6 +2084,19 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return rets; } + private String findDefaultDhcpIp(long userVmId) { + NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId); + + //check if the DhcpProvider is the domR + if (!_networkMgr.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter)) { + return null; + } + + //find domR's nic in the network + NicVO domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter); + return domrDefaultNic.getIp4Address(); + } + @Override public List applyUserData(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, List routers) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { @@ -2552,7 +2566,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.debug("Creating dhcp entry for vm " + vm + " on domR " + router + "."); DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), vm.getHostName()); - dhcpCommand.setDefaultRouter(_nicDao.findDefaultNicForVM(vm.getId()).getGateway()); + dhcpCommand.setDefaultRouter(findDefaultDhcpIp(vm.getId())); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, router.getPrivateIpAddress()); dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); @@ -3000,4 +3014,5 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } return 0; } + }