[virt-tools-list] [virt-manager PATCH v2 1/9] inspection: extract vmmInspection._process_vm
Richard W.M. Jones
rjones at redhat.com
Thu Feb 23 10:50:07 UTC 2017
On Thu, Feb 23, 2017 at 11:22:19AM +0100, Pino Toscano wrote:
> Move the code that does the inspection handling of a VM to an own
> function, so it can be used as-is later on.
>
> It is just code motion.
Using 'git show -w' makes this easier to review, and indeed it
is just a simple refactoring.
ACK from me.
Rich.
> virtManager/inspection.py | 68 +++++++++++++++++++++++++----------------------
> 1 file changed, 36 insertions(+), 32 deletions(-)
>
> diff --git a/virtManager/inspection.py b/virtManager/inspection.py
> index b6dae58..53aa0c4 100644
> --- a/virtManager/inspection.py
> +++ b/virtManager/inspection.py
> @@ -121,40 +121,44 @@ class vmmInspection(vmmGObject):
> if not conn.is_active():
> break
>
> - def set_inspection_error(vm):
> - data = vmmInspectionData()
> - data.error = True
> + self._process_vm(conn, vm)
> +
> + # Try processing a single VM, keeping into account whether it was
> + # visited already, and whether there are cached data for it.
> + def _process_vm(self, conn, vm):
> + def set_inspection_error(vm):
> + data = vmmInspectionData()
> + data.error = True
> + self._set_vm_inspection_data(vm, data)
> +
> + vmuuid = vm.get_uuid()
> + prettyvm = vmuuid
> + try:
> + prettyvm = conn.get_uri() + ":" + vm.get_name()
> +
> + if vmuuid in self._vmseen:
> + data = self._cached_data.get(vmuuid)
> + if not data:
> + return
> +
> + if vm.inspection != data:
> + logging.debug("Found cached data for %s", prettyvm)
> self._set_vm_inspection_data(vm, data)
> + return
>
> - vmuuid = vm.get_uuid()
> - prettyvm = vmuuid
> - try:
> - prettyvm = conn.get_uri() + ":" + vm.get_name()
> -
> - if vmuuid in self._vmseen:
> - data = self._cached_data.get(vmuuid)
> - if not data:
> - continue
> -
> - if vm.inspection != data:
> - logging.debug("Found cached data for %s", prettyvm)
> - self._set_vm_inspection_data(vm, data)
> - continue
> -
> - # Whether success or failure, we've "seen" this VM now.
> - self._vmseen[vmuuid] = True
> - try:
> - data = self._process(conn, vm)
> - if data:
> - self._set_vm_inspection_data(vm, data)
> - else:
> - set_inspection_error(vm)
> - except:
> - set_inspection_error(vm)
> - raise
> - except:
> - logging.exception("%s: exception while processing",
> - prettyvm)
> + # Whether success or failure, we've "seen" this VM now.
> + self._vmseen[vmuuid] = True
> + try:
> + data = self._process(conn, vm)
> + if data:
> + self._set_vm_inspection_data(vm, data)
> + else:
> + set_inspection_error(vm)
> + except:
> + set_inspection_error(vm)
> + raise
> + except:
> + logging.exception("%s: exception while processing", prettyvm)
>
> def _process(self, conn, vm):
> if re.search(r"^guestfs-", vm.get_name()):
> --
> 2.9.3
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://libguestfs.org
More information about the virt-tools-list
mailing list