From: Ondrej Lichtner <olichtne(a)redhat.com>
The connection to libvirt should only be initialized if it's going to be
used. This should solve problems with LNST crashing because of libvirt
errors when running recipes that don't use virtual machines.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/VirtUtils.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index 9d2a6ff..54baabc 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -20,7 +20,12 @@ from lnst.Common.NetUtils import scan_netdevs
#this is a global object because opening the connection to libvirt in every
#object instance that uses it sometimes fails - the libvirt server probably
#can't handle that many connections at a time
-_libvirt_conn = libvirt.open(None)
+_libvirt_conn = None
+
+def init_libvirt_con():
+ global _libvirt_conn
+ if _libvirt_conn is None:
+ _libvirt_conn = libvirt.open(None)
class VirtUtilsError(Exception):
pass
@@ -74,6 +79,8 @@ class VirtDomainCtl:
self._name = domain_name
self._created_interfaces = {}
+ init_libvirt_con()
+
try:
self._domain = _libvirt_conn.lookupByName(domain_name)
except:
@@ -147,6 +154,8 @@ class VirtNetCtl(NetCtl):
"""
def __init__(self, name=None):
+ init_libvirt_con()
+
if not name:
name = self._generate_name()
self._name = name
--
2.6.4