[virt-tools-list] [PATCH 3/3] [NOT TO BE APPLIED] inspection: Pass log messages from libguestfs through the virt-manager logging system.

Richard W.M. Jones rjones at redhat.com
Fri Jun 28 16:57:05 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

This requires libguestfs >= 1.16, but that's older than the minimum
supported version of libguestfs, and even Ubuntu has libguestfs 1.18.
---
 virtManager/inspection.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/virtManager/inspection.py b/virtManager/inspection.py
index eb50a95..da74541 100644
--- a/virtManager/inspection.py
+++ b/virtManager/inspection.py
@@ -23,7 +23,7 @@ import logging
 import os
 import re
 
-from guestfs import GuestFS  # pylint: disable=F0401
+import guestfs
 
 from virtManager.baseclass import vmmGObject
 from virtManager.domain import vmmInspectionData
@@ -150,7 +150,6 @@ class vmmInspection(vmmGObject):
                           vm.get_name())
             return
 
-        g = GuestFS()
         prettyvm = conn.get_uri() + ":" + vm.get_name()
         ignore = vmuuid
 
@@ -165,6 +164,23 @@ class vmmInspection(vmmGObject):
             logging.debug("%s: nothing to inspect", prettyvm)
             return
 
+        # Create libguestfs handle.
+        g = guestfs.GuestFS()
+
+        # Ensure we capture all log messages into the virt-manager
+        # logging system.
+        def log_callback(ev, eh, buf, array):
+            ignore = eh
+            ignore = array
+            if ev == guestfs.EVENT_APPLIANCE:
+                buf = buf.rstrip()
+            logging.debug("%s", buf)
+
+        events = guestfs.EVENT_LIBRARY
+        if g.get_trace():   events |= guestfs.EVENT_TRACE
+        if g.get_verbose(): events |= guestfs.EVENT_APPLIANCE
+        g.set_event_callback(log_callback, events)
+
         # Add the disks.  Note they *must* be added with readonly flag set.
         for disk in disks:
             path = disk.path
-- 
1.8.2.1




More information about the virt-tools-list mailing list