VPC: update public IP info in domain_router table once the VR gets the public nic

This commit is contained in:
Alena Prokharchyk 2012-06-27 17:41:27 -07:00
parent 308fd39a73
commit 46b97cbf7d
3 changed files with 24 additions and 6 deletions

View File

@ -729,7 +729,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (dcVo.getNetworkType() == NetworkType.Basic) {
cmd.addVmData("metadata", "public-ipv4", guestIpAddress);
cmd.addVmData("metadata", "public-hostname", StringUtils.unicodeEscape(vmName));
}else
} else
{
if (router.getPublicIpAddress() == null) {
cmd.addVmData("metadata", "public-ipv4", guestIpAddress);

View File

@ -309,7 +309,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
} else {
result = false;
s_logger.warn("Failed to plug nic for " + ipAddress + " to VPC router " + router);
s_logger.warn("Failed to add public ip " + ipAddress + " to VPC router " + router);
}
} catch (Exception ex) {
s_logger.warn("Failed to add ip address " + ipAddress + " from the public network " + publicNetwork +
@ -748,7 +748,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
try {
//add VPC router to public networks
List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
for (Nic publicNic : publicNics.keySet()) {
Network publicNtwk = publicNics.get(publicNic);
IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
@ -757,7 +757,15 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
if (userIp.isSourceNat()) {
PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
publicIps.add(publicIp);
sourceNat.add(publicIp);
if (router.getPublicIpAddress() == null) {
DomainRouterVO routerVO = _routerDao.findById(router.getId());
routerVO.setPublicIpAddress(publicNic.getIp4Address());
routerVO.setPublicNetmask(publicNic.getNetmask());
routerVO.setPublicMacAddress(publicNic.getMacAddress());
_routerDao.update(routerVO.getId(), routerVO);
}
}
PlugNicCommand plugNicCmd = new PlugNicCommand(_itMgr.toVmTO(profile), getNicTO(router, publicNic.getNetworkId()));
@ -765,8 +773,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
// create ip assoc for source nat
if (!publicIps.isEmpty()) {
createVpcAssociateIPCommands(router, publicIps, cmds);
if (!sourceNat.isEmpty()) {
createVpcAssociateIPCommands(router, sourceNat, cmds);
}
for (Nic guestNic : guestNics.keySet()) {

View File

@ -1051,5 +1051,15 @@ public class NetUtils {
return true;
}
public static boolean isNetworksOverlap(String cidrA, String cidrB) {
Long[] cidrALong = cidrToLong(cidrA);
Long[] cidrBLong = cidrToLong(cidrB);
if (cidrALong == null || cidrBLong == null) {
return false;
}
long shift = 32 - (cidrALong[1] > cidrBLong[1] ? cidrBLong[1] : cidrALong[1]);
return ((cidrALong[0] >> shift) == (cidrBLong[0] >> shift));
}
}