From e6427f97dc02c87535ef9647e3d728106f6c3bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Wed, 18 Jul 2018 23:50:54 +0200 Subject: [PATCH] Helper function that lists where a given VM is used A helper function to list vm's usage added to the utils. --- qubesadmin/utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qubesadmin/utils.py b/qubesadmin/utils.py index edaac11..4e0a4e9 100644 --- a/qubesadmin/utils.py +++ b/qubesadmin/utils.py @@ -115,3 +115,29 @@ def updates_vms_status(qvm_collection): # "mixed" return None return status + +# Helper function that returns a list of all the places a given VM is used in. +# Output is a list of tuples (property_holder, property_name), with None as +# property_holder for global properties + + +def vm_usage(app, reference_vm): + + result = [] + + global_properties = ['default_dispvm', 'default_netvm', + 'default_template', 'clockvm', 'updatevm'] + + for prop in global_properties: + if reference_vm == getattr(app, prop, None): + result.append([None, prop]) + + vm_properties = ['template', 'netvm', 'default_dispvm'] + + for vm in app.domains: + for prop in vm_properties: + if reference_vm == getattr(vm, prop, None) and \ + not vm.property_is_default(prop): + result.append([vm, prop]) + + return result