__init__.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. '''Qubes VM objects.'''
  21. import qubesmgmt.base
  22. class QubesVM(qubesmgmt.base.PropertyHolder):
  23. '''Qubes domain.'''
  24. def __init__(self, app, name, vm_class):
  25. self._class = vm_class
  26. super(QubesVM, self).__init__(app, 'mgmt.vm.property.', name)
  27. @property
  28. def name(self):
  29. '''Domain name'''
  30. return self._method_dest
  31. @name.setter
  32. def name(self, new_value):
  33. self.qubesd_call(
  34. self._method_dest,
  35. self._method_prefix + 'Set',
  36. 'name',
  37. str(new_value).encode('utf-8'))
  38. self._method_dest = new_value
  39. self.app.domains.clear_cache()
  40. def start(self):
  41. '''
  42. Start domain.
  43. :return:
  44. '''
  45. self.qubesd_call(self._method_dest, 'mgmt.vm.Start')
  46. def shutdown(self):
  47. '''
  48. Shutdown domain.
  49. :return:
  50. '''
  51. # TODO: force parameter
  52. # TODO: wait parameter (using event?)
  53. self.qubesd_call(self._method_dest, 'mgmt.vm.Shutdown')
  54. def kill(self):
  55. '''
  56. Kill domain (forcefuly shutdown).
  57. :return:
  58. '''
  59. self.qubesd_call(self._method_dest, 'mgmt.vm.Kill')
  60. def pause(self):
  61. '''
  62. Pause domain.
  63. Pause its execution without any prior notification.
  64. :return:
  65. '''
  66. self.qubesd_call(self._method_dest, 'mgmt.vm.Pause')
  67. def unpause(self):
  68. '''
  69. Unpause domain.
  70. Opposite to :py:meth:`pause`.
  71. :return:
  72. '''
  73. self.qubesd_call(self._method_dest, 'mgmt.vm.Unpause')
  74. def suspend(self):
  75. '''
  76. Suspend domain.
  77. Give domain a chance to prepare for suspend - for example suspend
  78. used PCI devices.
  79. :return:
  80. '''
  81. raise NotImplementedError
  82. #self.qubesd_call(self._method_dest, 'mgmt.vm.Suspend')
  83. def resume(self):
  84. '''
  85. Resume domain.
  86. Opposite to :py:meth:`suspend`.
  87. :return:
  88. '''
  89. raise NotImplementedError
  90. #self.qubesd_call(self._method_dest, 'mgmt.vm.Resume')