cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [33/50] [abbrv] git commit: CS-15743: disable static nat as a part of network resources cleanup
Date Tue, 31 Jul 2012 20:40:02 GMT
CS-15743: disable static nat as a part of network resources cleanup

Conflicts:

	server/src/com/cloud/network/NetworkManagerImpl.java
	server/src/com/cloud/network/rules/RulesManagerImpl.java


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

Branch: refs/heads/vpc
Commit: 372568cb9a394179d3f5d116a23f43e68e04dc6a
Parents: 4507df0
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Mon Jul 30 10:46:09 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Mon Jul 30 11:08:33 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |    6 ++
 .../src/com/cloud/network/rules/RulesManager.java  |    9 ++
 .../com/cloud/network/rules/RulesManagerImpl.java  |   70 +++++++++++----
 3 files changed, 68 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/372568cb/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 2556588..5a2b017 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -5692,6 +5692,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
             success = false;
         }
 
+        //release all static nats for the network
+        if (!_rulesMgr.applyStaticNatForNetwork(networkId, false, caller, true)) {
+            s_logger.warn("Failed to disable static nats as part of shutdownNetworkRules
for network id " + networkId);
+            success = false;
+        }
+
         // Get all ip addresses, mark as releasing and release them on the backend
         Network network = getNetwork(networkId);
         List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(networkId,
null);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/372568cb/server/src/com/cloud/network/rules/RulesManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManager.java b/server/src/com/cloud/network/rules/RulesManager.java
index 072cfc9..4b83e04 100644
--- a/server/src/com/cloud/network/rules/RulesManager.java
+++ b/server/src/com/cloud/network/rules/RulesManager.java
@@ -78,4 +78,13 @@ public interface RulesManager extends RulesService {
 
     boolean disableStaticNat(long ipAddressId, Account caller, long callerUserId, boolean
releaseIpIfElastic) throws ResourceUnavailableException;
 
+    /**
+     * @param networkId
+     * @param continueOnError
+     * @param caller
+     * @param forRevoke
+     * @return
+     */
+    boolean applyStaticNatForNetwork(long networkId, boolean continueOnError, Account caller,
boolean forRevoke);
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/372568cb/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index b45443e..d00835e 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -1173,13 +1173,58 @@ public class RulesManagerImpl implements RulesManager, RulesService,
Manager {
 
     @Override
     public boolean applyStaticNatForIp(long sourceIpId, boolean continueOnError, Account
caller, boolean forRevoke) {
+        IpAddress sourceIp = _ipAddressDao.findById(sourceIpId);
+        
+        List<StaticNat> staticNats = createStaticNatForIp(sourceIp, caller, forRevoke);
 
+        if (staticNats != null && !staticNats.isEmpty()) {
+            try {
+                if (!_networkMgr.applyStaticNats(staticNats, continueOnError)) {
+                    return false;
+                }
+            } catch (ResourceUnavailableException ex) {
+                s_logger.warn("Failed to create static nat rule due to ", ex);
+                return false;
+            }
+        }
+
+        return true;
+    }
+    
+    
+    @Override
+    public boolean applyStaticNatForNetwork(long networkId, boolean continueOnError, Account
caller, boolean forRevoke) {
+        List<? extends IpAddress> staticNatIps = _ipAddressDao.listStaticNatPublicIps(networkId);
+        
         List<StaticNat> staticNats = new ArrayList<StaticNat>();
-        IpAddress sourceIp = _ipAddressDao.findById(sourceIpId);
+        for (IpAddress staticNatIp : staticNatIps) {
+            staticNats.addAll(createStaticNatForIp(staticNatIp, caller, forRevoke));
+        }
 
+        if (staticNats != null && !staticNats.isEmpty()) {
+            if (forRevoke) {
+                s_logger.debug("Found " + staticNats.size() + " static nats to disable for
network id " + networkId);
+            }
+            try {
+                if (!_networkMgr.applyStaticNats(staticNats, continueOnError)) {
+                    return false;
+                }
+            } catch (ResourceUnavailableException ex) {
+                s_logger.warn("Failed to create static nat rule due to ", ex);
+                return false;
+            }
+        } else {
+            s_logger.debug("Found 0 static nat rules to apply for network id " + networkId);
+        }
+
+        return true;
+    }
+
+    protected List<StaticNat> createStaticNatForIp(IpAddress sourceIp, Account caller,
boolean forRevoke) {
+        List<StaticNat> staticNats = new ArrayList<StaticNat>();
         if (!sourceIp.isOneToOneNat()) {
-            s_logger.debug("Source ip id=" + sourceIpId + " is not one to one nat");
-            return true;
+            s_logger.debug("Source ip id=" + sourceIp + " is not one to one nat");
+            return staticNats;
         }
 
         Long networkId = sourceIp.getAssociatedWithNetworkId();
@@ -1190,8 +1235,8 @@ public class RulesManagerImpl implements RulesManager, RulesService,
Manager {
         UserVmVO vm = _vmDao.findById(sourceIp.getAssociatedWithVmId());
         Network network = _networkMgr.getNetwork(networkId);
         if (network == null) {
-        	CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address
to map to specified vm id");
-        	ex.addProxyObject(vm, vm.getId(), "vmId");            
+            CloudRuntimeException ex = new CloudRuntimeException("Unable to find an ip address
to map to specified vm id");
+            ex.addProxyObject(vm, vm.getId(), "vmId");
             throw ex;
         }
 
@@ -1209,19 +1254,10 @@ public class RulesManagerImpl implements RulesManager, RulesService,
Manager {
             dstIp = _networkMgr.getIpInNetwork(sourceIp.getAssociatedWithVmId(), networkId);
         }
 
-        StaticNatImpl staticNat = new StaticNatImpl(sourceIp.getAllocatedToAccountId(), sourceIp.getAllocatedInDomainId(),
networkId, sourceIpId, dstIp, forRevoke);
+        StaticNatImpl staticNat = new StaticNatImpl(sourceIp.getAllocatedToAccountId(), sourceIp.getAllocatedInDomainId(),
+                networkId, sourceIp.getId(), dstIp, forRevoke);
         staticNats.add(staticNat);
-
-        try {
-            if (!_networkMgr.applyStaticNats(staticNats, continueOnError)) {
-                return false;
-            }
-        } catch (ResourceUnavailableException ex) {
-            s_logger.warn("Failed to create static nat rule due to ", ex);
-            return false;
-        }
-
-        return true;
+        return staticNats;
     }
 
     @Override


Mime
View raw message