cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject git commit: updated refs/heads/4.2-forward to a0f23d0
Date Thu, 22 Aug 2013 13:18:50 GMT
Updated Branches:
  refs/heads/4.2-forward 64460df55 -> a0f23d0f9


CLOUDSTACK-4442: Source NAT not applied when network starts up

ensure on network implement/restart/shutdown an ip assoc is sent so that
source nat ip is associated with source nat service provider.


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

Branch: refs/heads/4.2-forward
Commit: a0f23d0f94a825d0370e79f5e81f9bdc52cb8b93
Parents: 64460df
Author: Murali Reddy <muralimmreddy@gmail.com>
Authored: Thu Aug 22 18:45:33 2013 +0530
Committer: Murali Reddy <muralimmreddy@gmail.com>
Committed: Thu Aug 22 18:45:33 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManager.java   |  2 +-
 .../com/cloud/network/NetworkManagerImpl.java   | 42 +++++++++++++++-----
 .../cloud/network/MockNetworkManagerImpl.java   |  2 +-
 .../com/cloud/vpc/MockNetworkManagerImpl.java   |  2 +-
 4 files changed, 34 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f23d0f/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 6912b2b..f37407f 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -181,7 +181,7 @@ public interface NetworkManager  {
 
     UserDataServiceProvider getSSHKeyResetProvider(Network network);
 
-    boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException;
+    boolean applyIpAssociations(Network network, boolean continueOnError, boolean reprogramNetworkRules)
throws ResourceUnavailableException;
     
     boolean applyIpAssociations(Network network, boolean rulesRevoked, boolean continueOnError,
List<? extends PublicIpAddress> publicIps) throws ResourceUnavailableException;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f23d0f/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 c1a6791..472336c 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -634,17 +634,37 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         }
     }
 
-    
-
     @Override
-    public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException
{
+    public boolean applyIpAssociations(Network network, boolean continueOnError, boolean
reprogramNetworkRules) throws ResourceUnavailableException {
         List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(),
null);
         boolean success = true;
 
-        // CloudStack will take a lazy approach to associate an acquired public IP to a network
service provider as
+        // applyIpAssociations is invoked in below cases
+        //    - associate/dis-associate ip address to a network
+        //    - network restart/implement/shutdown
+        //
+        // For network restart/implement operations that trigger reprogramming network rules
run the the Ip Assoc
+        // so that source nat ip is associated with source nat service provider.
+        //
+        // for the associate/disassociate ip take a lazy approach to associate a public IP
to a network service provider as
         // it will not know what service an acquired IP will be used for. An IP is actually
associated with a provider when first
         // rule is applied. Similarly when last rule on the acquired IP is revoked, IP is
not associated with any provider
-        // but still be associated with the account. At this point just mark IP as allocated
or released.
+        // so at this point just mark IP as allocated or released.
+
+        if (reprogramNetworkRules) {
+            List<PublicIp> publicIps = new ArrayList<PublicIp>();
+            if (userIps != null && !userIps.isEmpty()) {
+                for (IPAddressVO userIp : userIps) {
+                    PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
+                    publicIps.add(publicIp);
+                }
+            }
+            if (! applyIpAssociations(network, false, continueOnError, publicIps)) {
+                return false;
+            }
+        }
+
+
         for (IPAddressVO addr : userIps) {
             if (addr.getState() == IpAddress.State.Allocating) {
                 addr.setAssociatedWithNetworkId(network.getId());
@@ -982,7 +1002,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
 
         boolean success = false;
         try {
-            success = applyIpAssociations(network, false);
+            success = applyIpAssociations(network, false, false);
             if (success) {
                 s_logger.debug("Successfully associated ip address " + ip.getAddress().addr()
+ " to network " + network);
             } else {
@@ -995,7 +1015,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                     try {
                         s_logger.warn("Failed to associate ip address, so releasing ip from
the database " + ip);
                         _ipAddressDao.markAsUnavailable(ip.getId());
-                        if (!applyIpAssociations(network, true)) {
+                        if (!applyIpAssociations(network, true, false)) {
                             // if fail to apply ip assciations again, unassign ip address
without updating resource
                             // count and generating usage event as there is no need to keep
it in the db
                             _ipAddressDao.unassignIpAddress(ip.getId());
@@ -1083,7 +1103,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         _ipAddressDao.update(ipId, ip);
 
         try {
-            boolean success = applyIpAssociations(network, false);
+            boolean success = applyIpAssociations(network, false, false);
             if (success) {
                 s_logger.debug("Successfully associated ip address " + ip.getAddress().addr()
+ " to network " + network);
             } else {
@@ -1224,7 +1244,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         if (ip.getAssociatedWithNetworkId() != null) {
             Network network = _networksDao.findById(ip.getAssociatedWithNetworkId());
             try {
-                if (!applyIpAssociations(network, true)) {
+                if (!applyIpAssociations(network, true, false)) {
                     s_logger.warn("Unable to apply ip address associations for " + network);
                     success = false;
                 }
@@ -3418,7 +3438,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
     protected boolean reprogramNetworkRules(long networkId, Account caller, NetworkVO network)
throws ResourceUnavailableException {
         boolean success = true;
         // associate all ip addresses
-        if (!applyIpAssociations(network, false)) {
+        if (!applyIpAssociations(network, false, true)) {
             s_logger.warn("Failed to apply ip addresses as a part of network id" + networkId
+ " restart");
             success = false;
         }
@@ -4038,7 +4058,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         }
 
         try {
-            if (!applyIpAssociations(network, true)) {
+            if (!applyIpAssociations(network, true, true)) {
                 s_logger.warn("Unable to apply ip address associations for " + network);
                 success = false;
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f23d0f/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index 9358c00..4d4b3af 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -295,7 +295,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
 
 
     @Override
-    public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException
{
+    public boolean applyIpAssociations(Network network, boolean continueOnError, boolean
reprogramNetworkRules) throws ResourceUnavailableException {
         // TODO Auto-generated method stub
         return false;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f23d0f/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index 45d6208..03e1524 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -920,7 +920,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
      * @see com.cloud.network.NetworkManager#applyIpAssociations(com.cloud.network.Network,
boolean)
      */
     @Override
-    public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException
{
+    public boolean applyIpAssociations(Network network, boolean continueOnError, boolean
reprogramNetworkRules) throws ResourceUnavailableException {
         // TODO Auto-generated method stub
         return false;
     }


Mime
View raw message