From 3dce4e974270d47fff67846d7659272ca9589b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sat, 10 Aug 2019 22:08:28 +0200 Subject: [PATCH] qubesadmin: define methods list_vmclass and list_devicesclass Adapt also previous direct calls of qubesdb QubesOS/qubes-issues#5213 --- qubesadmin/app.py | 12 ++++++++++++ qubesadmin/devices.py | 14 ++------------ qubesadmin/tools/qvm_create.py | 5 ++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/qubesadmin/app.py b/qubesadmin/app.py index 61ceb75..e1469d6 100644 --- a/qubesadmin/app.py +++ b/qubesadmin/app.py @@ -165,6 +165,18 @@ class QubesBase(qubesadmin.base.PropertyHolder): self._pool_drivers = None self.log = logging.getLogger('app') + def list_vmclass(self): + """Call Qubesd in order to obtain the vm classes list""" + vmclass = self.qubesd_call('dom0', 'admin.vmclass.List')\ + .decode().splitlines() + return sorted(vmclass) + + def list_deviceclass(self): + """Call Qubesd in order to obtain the device classes list""" + deviceclasses = self.qubesd_call('dom0', 'admin.deviceclass.List')\ + .decode().splitlines() + return sorted(deviceclasses) + def _refresh_pool_drivers(self): """ Refresh cached storage pool drivers and their parameters. diff --git a/qubesadmin/devices.py b/qubesadmin/devices.py index 646ef2d..c09e1ce 100644 --- a/qubesadmin/devices.py +++ b/qubesadmin/devices.py @@ -303,17 +303,7 @@ class DeviceManager(dict): return self[key] def __iter__(self): - return iter(self._get_device_classes()) + return iter(self._vm.app.list_deviceclass()) def keys(self): - return self._get_device_classes() - - def _get_device_classes(self): - """Function used to call Qubesd in order to obtain - the device classes list - """ - device_classes = \ - self._vm.app.qubesd_call('dom0', 'admin.deviceclass.List').decode() - device_classes = sorted(device_classes.splitlines()) - - return device_classes + return self._vm.app.list_deviceclass() diff --git a/qubesadmin/tools/qvm_create.py b/qubesadmin/tools/qvm_create.py index b7ded60..9dbcbe1 100644 --- a/qubesadmin/tools/qvm_create.py +++ b/qubesadmin/tools/qvm_create.py @@ -103,9 +103,8 @@ def main(args=None, app=None): args = parser.parse_args(args, app=app) if args.help_classes: - vm_classes = args.app.qubesd_call('dom0', 'admin.vmclass.List').decode() - vm_classes = vm_classes.splitlines() - print('\n'.join(sorted(vm_classes))) + vm_classes = args.app.list_vmclass() + print('\n'.join(vm_classes)) return 0 pools = {}