commit d16a5fb2ad16bb1b344747657fc58e4271c96850
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Mon Aug 22 10:24:35 2011 +0200
Handle error in creating libvirt object
virt-who.py | 8 ++++++--
virt.py | 8 +++++++-
2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 29d2fbf..8c52701 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -22,7 +22,7 @@ import sys
import os
import time
-from virt import Virt
+from virt import Virt, VirtError
from event import virEventLoopPureStart
from subscriptionmanager import SubscriptionManager
@@ -60,7 +60,11 @@ if __name__ == '__main__':
logger.error("Error in reading configuration file (/etc/rhsm/rhsm.conf):
%s" % e)
sys.exit(2)
- virt = Virt(logger)
+ try:
+ virt = Virt(logger)
+ except VirtError, e:
+ print e
+ sys.exit(3)
subscriptionManager.connect()
diff --git a/virt.py b/virt.py
index 206ff6f..0163c00 100644
--- a/virt.py
+++ b/virt.py
@@ -20,12 +20,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
import libvirt
+class VirtError(Exception):
+ pass
+
class Virt:
""" Class for interacting with libvirt. """
def __init__(self, logger):
self.changedCallback = None
self.logger = logger
- self.virt = libvirt.openReadOnly("")
+ try:
+ self.virt = libvirt.openReadOnly("")
+ except libvirt.libvirtError, e:
+ raise VirtError(str(e))
# Log libvirt errors
libvirt.registerErrorHandler(lambda ctx, error: self.logger.debug(error), None)