incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [1/12] git commit: VPC: update public IP info in domain_router table once the VR gets the public nic
Date Thu, 28 Jun 2012 17:25:07 GMT
Updated Branches:
  refs/heads/vpc ce876e24d -> 46b97cbf7


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


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/46b97cbf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/46b97cbf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/46b97cbf

Branch: refs/heads/vpc
Commit: 46b97cbf7d477a6a52c78369475c90172bf43791
Parents: 308fd39
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Wed Jun 27 17:41:27 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Jun 28 10:25:24 2012 -0700

----------------------------------------------------------------------
 .../router/VirtualNetworkApplianceManagerImpl.java |    2 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java     |   18 ++++++++++----
 utils/src/com/cloud/utils/net/NetUtils.java        |   10 ++++++++
 3 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/46b97cbf/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index a56ebb0..595d494 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/46b97cbf/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 76ff190..56c599c 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -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()) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/46b97cbf/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 886f441..0d3879d 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -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));
+    }
 
 }


Mime
View raw message