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

Cole Robinson crobinso at redhat.com
Fri Jun 28 17:00:29 UTC 2013


On 06/28/2013 12:57 PM, Richard W.M. Jones wrote:
> 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
> 

While I wouldn't want to do this unconditionally, we could keep this code
around and only enable it if a guestfs_debug global variable is set.

And we should be able to handle the version with a couple hasattr checks.

- Cole




More information about the virt-tools-list mailing list