incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [43/50] [abbrv] git commit: refs/heads/affinity_groups - CLOUDSTACK-1170: Use a unified way to generate PublicIp
Date Thu, 14 Mar 2013 22:35:17 GMT
CLOUDSTACK-1170: Use a unified way to generate PublicIp

Tired of manually generate mac address everytime when create PublicIp object.


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

Branch: refs/heads/affinity_groups
Commit: 8da60b39c1cf918a8d9bb9793d826d62cc380b4a
Parents: 6fac85f
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Wed Feb 27 13:59:02 2013 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Thu Mar 14 15:13:59 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   18 +++++---------
 server/src/com/cloud/network/NetworkModelImpl.java |    7 ++---
 .../src/com/cloud/network/NetworkServiceImpl.java  |    2 +-
 server/src/com/cloud/network/addr/PublicIp.java    |    4 +++
 .../router/VirtualNetworkApplianceManagerImpl.java |    3 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java     |    6 +---
 .../src/com/cloud/network/vpc/VpcManagerImpl.java  |    3 +-
 7 files changed, 19 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 82893c4..f527b73 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -355,9 +355,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
             _firewallMgr.addSystemFirewallRules(addr, owner);
         }
 
-        long macAddress = NetUtils.createSequenceBasedMacAddress(addr.getMacAddress());
-
-        return new PublicIp(addr, _vlanDao.findById(addr.getVlanId()), macAddress);
+        return PublicIp.createFromAddrAndVlan(addr, _vlanDao.findById(addr.getVlanId()));
     }
 
     @DB
@@ -404,8 +402,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
 
         PublicIp ipToReturn = null;
         if (sourceNatIp != null) {
-            ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()),
-                    NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress()));
+            ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()));
         } else {
             ipToReturn = assignDedicateIpAddress(owner, guestNetwork.getId(), null, dcId,
true);
         }
@@ -490,8 +487,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         List<PublicIp> publicIps = new ArrayList<PublicIp>();
         if (userIps != null && !userIps.isEmpty()) {
             for (IPAddressVO userIp : userIps) {
-                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
-                        NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                 publicIps.add(publicIp);
             }
         }
@@ -2311,7 +2307,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
             List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(),
null);
             if (userIps != null && !userIps.isEmpty()) {
                 for (IPAddressVO userIp : userIps) {
-    			PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+    			PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
     			publicIps.add(publicIp);
 	                }
              }
@@ -2847,7 +2843,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         List<PublicIp> publicIps = new ArrayList<PublicIp>();
         if (userIps != null && !userIps.isEmpty()) {
             for (IPAddressVO userIp : userIps) {
-                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                 publicIps.add(publicIp);
             }
         }
@@ -2877,7 +2873,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                         IPAddressVO ip = _ipAddressDao.findByIdIncludingRemoved(staticNat.getSourceIpAddressId());
                         // ip can't be null, otherwise something wrong happened
                         ip.setAssociatedWithVmId(null);
-                        publicIp = new PublicIp(ip, _vlanDao.findById(ip.getVlanId()), NetUtils.createSequenceBasedMacAddress(ip.getMacAddress()));
+                        publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
                         publicIps.add(publicIp);
                         break;
                     }
@@ -3154,7 +3150,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         if (userIps != null && !userIps.isEmpty()) {
             for (IPAddressVO userIp : userIps) {
                 userIp.setState(State.Releasing);
-                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                 publicIpsToRelease.add(publicIp);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index f978ac5..ac1bc87 100644
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -709,7 +709,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
             return null;
         }
     
-        return new PublicIp(addr, _vlanDao.findById(addr.getVlanId()), NetUtils.createSequenceBasedMacAddress(addr.getMacAddress()));
+        return PublicIp.createFromAddrAndVlan(addr, _vlanDao.findById(addr.getVlanId()));
     }
 
     @Override
@@ -1405,7 +1405,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
             return true;
         }
         IPAddressVO ipVO = _ipAddressDao.findById(userIp.getId());
-        PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(userIp.getVlanId()), NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+        PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipVO, _vlanDao.findById(userIp.getVlanId()));
         if (!canIpUsedForService(publicIp, service, networkId)) {
             return false;
         }
@@ -1884,8 +1884,7 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
             for (IpAddress addr : addrs) {
                 if (addr.isSourceNat()) {
                     sourceNatIp = _ipAddressDao.findById(addr.getId());
-                    return new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()),

-                            NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress()));
+                    return PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()));
                 }
             }
     

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index ce527b7..1708224 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -1895,7 +1895,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         List<PublicIp> publicIps = new ArrayList<PublicIp>();
         if (userIps != null && !userIps.isEmpty()) {
             for (IPAddressVO userIp : userIps) {
-                PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),
NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                 publicIps.add(publicIp);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/server/src/com/cloud/network/addr/PublicIp.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/addr/PublicIp.java b/server/src/com/cloud/network/addr/PublicIp.java
index 7336c9c..61351a6 100644
--- a/server/src/com/cloud/network/addr/PublicIp.java
+++ b/server/src/com/cloud/network/addr/PublicIp.java
@@ -37,6 +37,10 @@ public class PublicIp implements PublicIpAddress {
         this.macAddress = NetUtils.long2Mac(macAddress);
     }
 
+    public static PublicIp createFromAddrAndVlan(IPAddressVO addr, VlanVO vlan) {
+    	return new PublicIp(addr, vlan, NetUtils.createSequenceBasedMacAddress(addr.getMacAddress()));
+    }
+    
     @Override
     public Ip getAddress() {
         return _addr.getAddress();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/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 abb4973..0e2eb63 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -2414,8 +2414,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                 
                 if (addIp) {
                     IPAddressVO ipVO = _ipAddressDao.findById(userIp.getId());
-                    PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(userIp.getVlanId()),

-                            NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
+                    PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipVO, _vlanDao.findById(userIp.getVlanId()));
                     allPublicIps.add(publicIp);
                 }
             }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/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 4d1968d..66fb03b 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -803,8 +803,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
                         publicNic.getIp4Address());
                
                 if (userIp.isSourceNat()) {
-                    PublicIp publicIp = new PublicIp(userIp, _vlanDao.findById(userIp.getVlanId()),

-                            NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
+                    PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                     sourceNat.add(publicIp);
                     
                     if (router.getPublicIpAddress() == null) {
@@ -1227,8 +1226,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         //4) allocate nic for additional public network(s)
         List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, false);
         for (IPAddressVO ip : ips) {
-            PublicIp publicIp = new PublicIp(ip, _vlanDao.findById(ip.getVlanId()), 
-                    NetUtils.createSequenceBasedMacAddress(ip.getMacAddress()));
+            PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
             if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating)

                     && _vpcMgr.ipUsedInVpc(ip)&& !publicVlans.contains(publicIp.getVlanTag()))
{
                 s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8da60b39/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index c9c13c9..de6707e 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -2014,8 +2014,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
         PublicIp ipToReturn = null;
 
         if (sourceNatIp != null) {
-            ipToReturn = new PublicIp(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()),

-                    NetUtils.createSequenceBasedMacAddress(sourceNatIp.getMacAddress()));
+            ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId()));
         } else {
             ipToReturn = _ntwkMgr.assignDedicateIpAddress(owner, null, vpc.getId(), dcId,
true);
         }


Mime
View raw message