You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2014/06/17 17:10:51 UTC

[2/2] git commit: updated refs/heads/4.3 to 9289158

CLOUDSTACK-6927: store virsh list in list instead of querying libvirt for each chain to speedup the function


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

Branch: refs/heads/4.3
Commit: 92891584067540b6718aede9ca4deda9a64de319
Parents: 199bc08
Author: Loic Lambiel <ll...@exoscale.ch>
Authored: Thu Jun 5 11:32:49 2014 +0200
Committer: Sebastien Goasguen <ru...@gmail.com>
Committed: Tue Jun 17 17:10:29 2014 +0200

----------------------------------------------------------------------
 scripts/vm/network/security_group.py | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/92891584/scripts/vm/network/security_group.py
----------------------------------------------------------------------
diff --git a/scripts/vm/network/security_group.py b/scripts/vm/network/security_group.py
index be61842..873fdef 100755
--- a/scripts/vm/network/security_group.py
+++ b/scripts/vm/network/security_group.py
@@ -688,6 +688,8 @@ def cleanup_rules():
         chainscmd = """iptables-save | awk '{for(i=1;i<=NF;i++){ if($i ~ /[i|r|s|v]-[0-9]/){print $i} } }'"""
         chains = execute(chainscmd).split('\n')
         cleanup = []
+        results = []
+        results = virshlist('paused', 'running')
         for chain in chains:
             if chain == "":
                 continue
@@ -700,14 +702,8 @@ def cleanup_rules():
 
             vm_name = chain
 
-            result = virshdomstate(vm_name)
-
-            if result == None or len(result) == 0:
-                logging.debug("chain " + chain + " does not correspond to a vm, cleaning up iptable rules")
-                cleanup.append(vm_name)
-                continue
-            if not (result == "running" or result == "paused"):
-                logging.debug("vm " + vm_name + " is not running or paused, cleaning up iptable rules")
+            if not vm_name in results:
+                logging.debug("chain " + chain + " does not correspond to a vm or vm is not running or paused, cleaning up iptable rules")
                 cleanup.append(vm_name)
 
         chainscmd = """ebtables-save | awk '{for(i=1;i<=NF;i++){ if($i ~ /[i|r|s|v]-[0-9]/){print $i} } }'"""
@@ -720,17 +716,11 @@ def cleanup_rules():
             if not chain.endswith("VM"):
                 chain = chain.split("VM")[0] + "VM"
 
-                vm_name = chain
-
-                result = virshdomstate(vm_name)
+            vm_name = chain
 
-                if result == None or len(result) == 0:
-                    logging.debug("chain " + chain + " does not correspond to a vm, cleaning up ebtable rules")
-                    cleanup.append(vm_name)
-                    continue
-                if not (result == "running" or result == "paused"):
-                    logging.debug("vm " + vm_name + " is not running or paused, cleaning up ebtable rules")
-                    cleanup.append(vm_name)
+            if not vm_name in results:
+                logging.debug("chain " + chain + " does not correspond to a vm or vm is not running or paused, cleaning up ebtable rules")
+                cleanup.append(vm_name)
 
         for vmname in cleanup:
             destroy_network_rules_for_vm(vmname)