[Kimchi-devel] [PATCH 1/3] move _default_network_check from top model to networks model
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Fri Mar 7 09:53:00 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
Top model should load other model and structure preparing.
The default network check is network function, move to networks model
is more reasonable.
And the important: it is more convenient to call attr of networks model
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/model/model.py | 35 -----------------------------------
src/kimchi/model/networks.py | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/src/kimchi/model/model.py b/src/kimchi/model/model.py
index aa5eab5..a7d843e 100644
--- a/src/kimchi/model/model.py
+++ b/src/kimchi/model/model.py
@@ -39,7 +39,6 @@ class Model(BaseModel):
if 'qemu:///' in libvirt_uri:
self._default_pool_check()
- self._default_network_check()
this = os.path.basename(__file__)
this_mod = os.path.splitext(this)[0]
@@ -58,40 +57,6 @@ class Model(BaseModel):
return super(Model, self).__init__(models)
- 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)
- except libvirt.libvirtError, e:
- cherrypy.log.error("Fatal: Cannot create default network "
- "because of %s, exit kimchid" % e.message,
- severity=logging.ERROR)
- sys.exit(1)
-
- if net.isActive() == 0:
- try:
- net.create()
- except libvirt.libvirtError, e:
- cherrypy.log.error("Fatal: Cannot activate default network "
- "because of %s, exit kimchid" % e.message,
- severity=logging.ERROR)
- sys.exit(1)
-
def _default_pool_check(self):
conn = self.conn.get()
xml = """
diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index f032875..bd9c03a 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -32,6 +32,42 @@ from kimchi.rollbackcontext import RollbackContext
class NetworksModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
+ if 'qemu:///' in self.conn.get().getURI():
+ self._default_network_check()
+
+ 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)
+ except libvirt.libvirtError, e:
+ cherrypy.log.error("Fatal: Cannot create default network "
+ "because of %s, exit kimchid" % e.message,
+ severity=logging.ERROR)
+ sys.exit(1)
+
+ if net.isActive() == 0:
+ try:
+ net.create()
+ except libvirt.libvirtError, e:
+ cherrypy.log.error("Fatal: Cannot activate default network "
+ "because of %s, exit kimchid" % e.message,
+ severity=logging.ERROR)
+ sys.exit(1)
def create(self, params):
conn = self.conn.get()
--
1.8.4.2
More information about the Kimchi-devel
mailing list