Skip to content

Commit

Permalink
api/internal: extract get_system_info() function
Browse files Browse the repository at this point in the history
This will be useful in other places too.

QubesOS/qubes-issues#5099
  • Loading branch information
marmarek committed Mar 9, 2020
1 parent 135eda0 commit 879ee9e
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions qubes/api/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
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.'''
Expand All @@ -42,19 +59,7 @@ def getsysteminfo(self):
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)

Expand Down

0 comments on commit 879ee9e

Please sign in to comment.