From 7ff01b631dd0369f714cf728628cc4212084e00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Tue, 6 Aug 2019 10:07:14 +0200 Subject: [PATCH] admin: add admin.deviceclass.List QubesOS/qubes-issues#5213 --- Makefile | 1 + qubes/api/admin.py | 13 +++++++++++++ qubes/tests/api_admin.py | 3 +++ 3 files changed, 17 insertions(+) diff --git a/Makefile b/Makefile index b60be2dc..cbb19d6a 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ OS ?= Linux PYTHON ?= python3 ADMIN_API_METHODS_SIMPLE = \ + admin.deviceclass.List \ admin.vmclass.List \ admin.Events \ admin.backup.Execute \ diff --git a/qubes/api/admin.py b/qubes/api/admin.py index d55b387e..c6205c3b 100644 --- a/qubes/api/admin.py +++ b/qubes/api/admin.py @@ -1146,6 +1146,19 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI): self.app.save() + @qubes.api.method('admin.deviceclass.List', no_payload=True, + scope='global', read=True) + @asyncio.coroutine + def deviceclass_list(self): + """List all DEVICES classes""" + self.enforce(not self.arg) + self.enforce(self.dest.name == 'dom0') + + entrypoints = self.fire_event_for_filter( + pkg_resources.iter_entry_points('qubes.devices')) + + return ''.join('{}\n'.format(ep.name) for ep in entrypoints) + @qubes.api.method('admin.vm.device.{endpoint}.Available', endpoints=(ep.name for ep in pkg_resources.iter_entry_points('qubes.devices')), no_payload=True, diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index ac577048..f5403957 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -2620,6 +2620,7 @@ class TC_00_VMs(AdminAPITestCase): def test_992_dom0_unexpected_payload(self): methods_with_no_payload = [ + b'admin.deviceclass.List', b'admin.vmclass.List', b'admin.vm.List', b'admin.label.List', @@ -2661,6 +2662,7 @@ class TC_00_VMs(AdminAPITestCase): def test_993_dom0_unexpected_argument(self): methods_with_no_argument = [ + b'admin.deviceclass.List', b'admin.vmclass.List', b'admin.vm.List', b'admin.label.List', @@ -2696,6 +2698,7 @@ class TC_00_VMs(AdminAPITestCase): # TODO set some better arguments, to make sure the call was rejected # because of invalid destination, not invalid arguments methods_for_dom0_only = [ + b'admin.deviceclass.List', b'admin.vmclass.List', b'admin.vm.Create.AppVM', b'admin.vm.CreateInPool.AppVM',