Browse Source

admin: add admin.deviceclass.List

QubesOS/qubes-issues#5213
Frédéric Pierret (fepitre) 4 years ago
parent
commit
7ff01b631d
3 changed files with 17 additions and 0 deletions
  1. 1 0
      Makefile
  2. 13 0
      qubes/api/admin.py
  3. 3 0
      qubes/tests/api_admin.py

+ 1 - 0
Makefile

@@ -8,6 +8,7 @@ OS ?= Linux
 PYTHON ?= python3
 
 ADMIN_API_METHODS_SIMPLE = \
+	admin.deviceclass.List \
 	admin.vmclass.List \
 	admin.Events \
 	admin.backup.Execute \

+ 13 - 0
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,

+ 3 - 0
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',