[Kimchi-devel] [PATCH 1/2] Implement function to discover which bridge name is available

Ramon Medeiros ramonn at linux.vnet.ibm.com
Thu Feb 12 18:02:50 UTC 2015


Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
 src/kimchi/model/networks.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index 7265c64..dd8e66c 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -17,6 +17,8 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
+import os
+import re
 import sys
 import time
 
@@ -81,6 +83,24 @@ class NetworksModel(object):
                                      "because of %s, exit kimchid", e.message)
                     sys.exit(1)
 
+    def _find_bridge_available(self, sufix):
+        # get all bridges
+        bridges = os.popen("brctl show | awk '{print $1}'").readlines()
+        bridges.remove("bridge\n")
+
+        # no bridge found: it number 0
+        bridgeName = sufix + str(0)
+
+        # iterate over all bridges to verify the correct number
+        for bridge in bridges:
+
+            # search for bridges with sufix: use next number
+            if bridge.startswith(sufix):
+                name, number = re.match(r"([a-z]*)([0-9]*)", bridge).groups()
+                bridgeName = sufix + str(int(number) + 1)
+
+        return bridgeName
+
     def create(self, params):
         conn = self.conn.get()
         name = params['name']
-- 
1.8.3.1




More information about the Kimchi-devel mailing list