Skip to content

Commit

Permalink
Create default network if it does not exist
Browse files Browse the repository at this point in the history
The default network must exist and be active in order to Kimchi manage virtual
machines without problems.
So verify if the default network exists and if not create and active it.

Signed-off-by: Aline Manera <alinefm@br.ibm.com>
  • Loading branch information
alinefm authored and Adam Litke committed Oct 1, 2013
1 parent 59efe0c commit 71a3a88
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/kimchi/model.py
Expand Up @@ -106,6 +106,41 @@ def __init__(self, libvirt_uri=None, objstore_loc=None):
self.statsThread.start()
if 'qemu:///' in self.libvirt_uri:
self._default_pool_check()
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 _default_pool_check(self):
default_pool = {'name': 'default',
Expand Down

0 comments on commit 71a3a88

Please sign in to comment.