mgmtinternal.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. ''' Internal interface for dom0 components to communicate with qubesd. '''
  21. import asyncio
  22. import json
  23. import qubes.mgmt
  24. import qubes.vm.dispvm
  25. api = qubes.mgmt.api
  26. class QubesInternalMgmt(qubes.mgmt.AbstractQubesMgmt):
  27. ''' Communication interface for dom0 components,
  28. by design the input here is trusted.'''
  29. #
  30. # PRIVATE METHODS, not to be called via RPC
  31. #
  32. #
  33. # ACTUAL RPC CALLS
  34. #
  35. @api('mgmtinternal.GetSystemInfo', no_payload=True)
  36. @asyncio.coroutine
  37. def getsysteminfo(self):
  38. assert self.dest.name == 'dom0'
  39. assert not self.arg
  40. system_info = {'domains': {
  41. domain.name: {
  42. 'tags': list(domain.tags),
  43. 'type': domain.__class__.__name__,
  44. 'dispvm_allowed': getattr(domain, 'dispvm_allowed', False),
  45. 'default_dispvm': (str(domain.default_dispvm) if
  46. domain.default_dispvm else None),
  47. 'icon': str(domain.label.icon),
  48. } for domain in self.app.domains
  49. }}
  50. return json.dumps(system_info)
  51. @api('mgmtinternal.vm.Start', no_payload=True)
  52. @asyncio.coroutine
  53. def start(self):
  54. assert not self.arg
  55. yield from self.dest.start()
  56. @api('mgmtinternal.vm.Create.DispVM', no_payload=True)
  57. @asyncio.coroutine
  58. def create_dispvm(self):
  59. assert not self.arg
  60. # TODO convert to coroutine
  61. dispvm = qubes.vm.dispvm.DispVM.from_appvm(self.dest)
  62. return dispvm.name
  63. @api('mgmtinternal.vm.CleanupDispVM', no_payload=True)
  64. @asyncio.coroutine
  65. def cleanup_dispvm(self):
  66. assert not self.arg
  67. # TODO convert to coroutine
  68. self.dest.cleanup()