bug 10804: Another fix for defaultNetwork feature - get the default Dhcp server IP from the domR's nic in vm's default network instead of getting it from the "gateway" field of the vm itself

This commit is contained in:
Alena Prokharchyk 2011-12-05 14:24:43 -08:00 committed by Jessica Wang
parent 7b8287d323
commit bba8e941ce
2 changed files with 18 additions and 4 deletions

View File

@ -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);

View File

@ -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<VirtualRouter> applyUserData(Network network, NicProfile nic, VirtualMachineProfile<UserVm> profile, DeployDestination dest, ReservationContext context, List<DomainRouterVO> 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;
}
}