[Kimchi-devel] [PATCH 3/3] Issue #302: let 'create' attr of networks model to create default network

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Fri Mar 7 09:53:02 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

Then the IP and Bridge name will not be hard coded.

Also in some scenarios, such as in nested KVM, the default network
created by kimchi on L2 guest can avoid the same network address of
L2.

https://github.com/kimchi-project/kimchi/issues/302

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/model/networks.py | 18 +++++-------------
 src/kimchi/network.py        |  3 +++
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index 7103085..4959add 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -37,23 +37,15 @@ class NetworksModel(object):
 
     def _default_network_check(self):
         conn = self.conn.get()
-        xml = """
-            <network>
-              <name>default</name>
-              <forward mode='nat'/>
-              <bridge name='virbr0' stp='on' delay='0' />
-              <ip address='192.168.122.1' netmask='255.255.255.0'>
-                <dhcp>
-                  <range start='192.168.122.2' end='192.168.122.254' />
-                </dhcp>
-              </ip>
-            </network>
-        """
         try:
             net = conn.networkLookupByName("default")
         except libvirt.libvirtError:
             try:
-                net = conn.networkDefineXML(xml)
+                subnet = self._get_available_address(knetwork.DefaultNetsPool)
+                params = {"name": "default", "connection": "nat",
+                          "subnet": subnet}
+                self.create(params)
+                net = conn.networkLookupByName("default")
             except libvirt.libvirtError, e:
                 cherrypy.log.error("Fatal: Cannot create default network "
                                    "because of %s, exit kimchid" % e.message,
diff --git a/src/kimchi/network.py b/src/kimchi/network.py
index 9ad95b4..9bf0c66 100644
--- a/src/kimchi/network.py
+++ b/src/kimchi/network.py
@@ -26,6 +26,9 @@ APrivateNets = ipaddr.IPNetwork("10.0.0.0/8")
 BPrivateNets = ipaddr.IPNetwork("172.16.0.0/12")
 CPrivateNets = ipaddr.IPNetwork('192.168.0.0/16')
 PrivateNets = [CPrivateNets, BPrivateNets, APrivateNets]
+DefaultNetsPool = [ipaddr.IPNetwork('192.168.122.0/23'),
+                   ipaddr.IPNetwork('192.168.124.0/22'),
+                   ipaddr.IPNetwork('192.168.128.0/17')]
 
 
 def get_dev_netaddr(dev):
-- 
1.8.4.2




More information about the Kimchi-devel mailing list