internal.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. yield from self.dest.start()
  56. @qubes.api.method('internal.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. @qubes.api.method('internal.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()