Discovery which bridge is available and pass it when creating the default network pool.
Ramon Medeiros (2):
Implement function to discover which bridge name is available
Pass bridge name on NAT network creation
src/kimchi/model/networks.py | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
--
1.8.3.1
Show replies by date
Signed-off-by: Ramon Medeiros <ramonn(a)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
Signed-off-by: Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
To avoid issue #556: Unable to create bridge virbr0: File already exists, which
happens because libvirt uses virbr0 as default bridge to create a
network pool. When this bridge is already created, libvirt raises and
error.
To fix, it will be passed an available bridge, that will be created by
libvirt.
---
src/kimchi/model/networks.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index dd8e66c..a3d350c 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -52,7 +52,8 @@ class NetworksModel(object):
try:
subnet = self._get_available_address(knetwork.DefaultNetsPool)
params = {"name": "default", "connection":
"nat",
- "subnet": subnet}
+ "subnet": subnet,
+ "bridge":
self._find_bridge_available("virbr")}
self.create(params)
return conn.networkLookupByName("default")
except Exception as e:
--
1.8.3.1