internal.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.api
  24. import qubes.api.admin
  25. import qubes.vm.dispvm
  26. class QubesInternalAPI(qubes.api.AbstractQubesAPI):
  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. @qubes.api.method('internal.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. @qubes.api.method('internal.vm.Start', no_payload=True)
  52. @asyncio.coroutine
  53. def start(self):
  54. assert not self.arg
  55. if self.dest.name == 'dom0':
  56. return
  57. yield from self.dest.start()
  58. @qubes.api.method('internal.vm.Create.DispVM', no_payload=True)
  59. @asyncio.coroutine
  60. def create_dispvm(self):
  61. assert not self.arg
  62. # TODO convert to coroutine
  63. dispvm = qubes.vm.dispvm.DispVM.from_appvm(self.dest)
  64. return dispvm.name
  65. @qubes.api.method('internal.vm.CleanupDispVM', no_payload=True)
  66. @asyncio.coroutine
  67. def cleanup_dispvm(self):
  68. assert not self.arg
  69. # TODO convert to coroutine
  70. self.dest.cleanup()