From 879ee9e7d6cea9deb817826c5e6a299660554828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 20 Feb 2020 05:38:50 +0100 Subject: [PATCH] api/internal: extract get_system_info() function This will be useful in other places too. QubesOS/qubes-issues#5099 --- qubes/api/internal.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/qubes/api/internal.py b/qubes/api/internal.py index 1f618fbb..19659a17 100644 --- a/qubes/api/internal.py +++ b/qubes/api/internal.py @@ -30,6 +30,23 @@ import qubes.vm.adminvm import qubes.vm.dispvm +def get_system_info(app): + system_info = {'domains': { + domain.name: { + 'tags': list(domain.tags), + 'type': domain.__class__.__name__, + 'template_for_dispvms': + getattr(domain, 'template_for_dispvms', False), + 'default_dispvm': (domain.default_dispvm.name if + getattr(domain, 'default_dispvm', None) else None), + 'icon': str(domain.label.icon), + 'guivm': (domain.guivm.name if getattr(domain, 'guivm', None) + else None), + } for domain in app.domains + }} + return system_info + + class QubesInternalAPI(qubes.api.AbstractQubesAPI): ''' Communication interface for dom0 components, by design the input here is trusted.''' @@ -42,19 +59,7 @@ class QubesInternalAPI(qubes.api.AbstractQubesAPI): self.enforce(self.dest.name == 'dom0') self.enforce(not self.arg) - system_info = {'domains': { - domain.name: { - 'tags': list(domain.tags), - 'type': domain.__class__.__name__, - 'template_for_dispvms': - getattr(domain, 'template_for_dispvms', False), - 'default_dispvm': (domain.default_dispvm.name if - getattr(domain, 'default_dispvm', None) else None), - 'icon': str(domain.label.icon), - 'guivm': (domain.guivm.name if getattr(domain, 'guivm', None) - else None), - } for domain in self.app.domains - }} + system_info = get_system_info(self.app) return json.dumps(system_info)