[virt-tools-list] [virt-manager PATCH] virt-manager, inspection: use add_libvirt_dom

Cole Robinson crobinso at redhat.com
Thu Jan 8 19:23:46 UTC 2015


ACK

- Cole

On 01/08/2015 09:12 AM, Giuseppe Scrivano wrote:
> From: "Richard W.M. Jones" <rjones at redhat.com>
> 
> Enable inspection only if the add_libvirt_dom function is present at
> runtime.
> 
> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1075143
> 
> Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
> ---
>  virtManager/config.py     |  4 ++--
>  virtManager/inspection.py | 29 +++--------------------------
>  2 files changed, 5 insertions(+), 28 deletions(-)
> 
> diff --git a/virtManager/config.py b/virtManager/config.py
> index 9258313..df649ab 100644
> --- a/virtManager/config.py
> +++ b/virtManager/config.py
> @@ -183,8 +183,8 @@ class vmmConfig(object):
>          try:
>              # Check we can open the Python guestfs module.
>              from guestfs import GuestFS  # pylint: disable=import-error
> -            GuestFS(close_on_exit=False)
> -            return True
> +            g = GuestFS(close_on_exit=False)
> +            return bool(getattr(g, "add_libvirt_dom", None))
>          except:
>              return False
>  
> diff --git a/virtManager/inspection.py b/virtManager/inspection.py
> index f5b8a89..e8b102d 100644
> --- a/virtManager/inspection.py
> +++ b/virtManager/inspection.py
> @@ -20,7 +20,6 @@
>  from Queue import Queue, Empty
>  from threading import Thread
>  import logging
> -import os
>  import re
>  
>  from guestfs import GuestFS  # pylint: disable=import-error
> @@ -145,7 +144,7 @@ class vmmInspection(vmmGObject):
>                      # Whether success or failure, we've "seen" this VM now.
>                      self._vmseen[vmuuid] = True
>                      try:
> -                        data = self._process(conn, vm, vmuuid)
> +                        data = self._process(conn, vm)
>                          if data:
>                              self._set_vm_inspection_data(vm, data)
>                          else:
> @@ -157,7 +156,7 @@ class vmmInspection(vmmGObject):
>                      logging.exception("%s: exception while processing",
>                                        prettyvm)
>  
> -    def _process(self, conn, vm, vmuuid):
> +    def _process(self, conn, vm):
>          if re.search(r"^guestfs-", vm.get_name()):
>              logging.debug("ignore libvirt/guestfs temporary VM %s",
>                            vm.get_name())
> @@ -165,30 +164,8 @@ class vmmInspection(vmmGObject):
>  
>          g = GuestFS(close_on_exit=False)
>          prettyvm = conn.get_uri() + ":" + vm.get_name()
> -        ignore = vmuuid
>  
> -        disks = []
> -        for disk in vm.get_disk_devices():
> -            if (disk.path and
> -                (disk.type == "block" or disk.type == "file") and
> -                not disk.device == "cdrom"):
> -                disks.append(disk)
> -
> -        if not disks:
> -            logging.debug("%s: nothing to inspect", prettyvm)
> -            return None
> -
> -        # Add the disks.  Note they *must* be added with readonly flag set.
> -        for disk in disks:
> -            path = disk.path
> -            driver_type = disk.driver_type
> -
> -            if not (os.path.exists(path) and os.access(path, os.R_OK)):
> -                logging.debug("%s: cannot access '%s', skipping inspection",
> -                              prettyvm, path)
> -                return None
> -
> -            g.add_drive_opts(path, readonly=1, format=driver_type)
> +        g.add_libvirt_dom(vm.get_backend(), readonly=1)
>  
>          g.launch()
>  
> 




More information about the virt-tools-list mailing list