adminvm.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, https://www.qubes-os.org/
  5. #
  6. # Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2013-2015 Marek Marczykowski-Górecki
  8. # <marmarek@invisiblethingslab.com>
  9. # Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License along
  22. # with this program; if not, write to the Free Software Foundation, Inc.,
  23. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. #
  25. import qubes
  26. import qubes.exc
  27. import qubes.vm.qubesvm
  28. class AdminVM(qubes.vm.qubesvm.QubesVM):
  29. '''Dom0'''
  30. dir_path = None
  31. netvm = qubes.property('netvm', setter=qubes.property.forbidden,
  32. default=None,
  33. doc='Dom0 cannot have netvm')
  34. kernel = qubes.property('netvm', setter=qubes.property.forbidden,
  35. default=None,
  36. doc='There are other ways to set kernel for Dom0.')
  37. @property
  38. def xid(self):
  39. '''Always ``0``.
  40. .. seealso:
  41. :py:attr:`qubes.vm.qubesvm.QubesVM.xid`
  42. '''
  43. return 0
  44. @property
  45. def libvirt_domain(self):
  46. '''Always :py:obj:`None`.
  47. .. seealso:
  48. :py:attr:`qubes.vm.qubesvm.QubesVM.libvirt_domain`
  49. '''
  50. return None
  51. # XXX probably unneeded, will return None as we don't have netvm
  52. # @property
  53. # def ip(self):
  54. # return "10.137.0.2"
  55. def is_running(self):
  56. '''Always :py:obj:`True`.
  57. .. seealso:
  58. :py:meth:`qubes.vm.qubesvm.QubesVM.is_running`
  59. '''
  60. return True
  61. def get_power_state(self):
  62. '''Always ``'Running'``.
  63. .. seealso:
  64. :py:meth:`qubes.vm.qubesvm.QubesVM.get_power_state`
  65. '''
  66. return 'Running'
  67. def get_mem(self):
  68. '''Get current memory usage of Dom0.
  69. Unit is KiB.
  70. .. seealso:
  71. :py:meth:`qubes.vm.qubesvm.QubesVM.get_mem`
  72. '''
  73. #return psutil.virtual_memory().total/1024
  74. for line in open('/proc/meminfo'):
  75. if line.startswith('MemTotal:'):
  76. return int(line.split(':')[1].strip().split()[0])
  77. raise NotImplementedError()
  78. def get_mem_static_max(self):
  79. '''Get maximum memory available to Dom0.
  80. .. seealso:
  81. :py:meth:`qubes.vm.qubesvm.QubesVM.get_mem_static_max`
  82. '''
  83. return self.app.vmm.libvirt_conn.getInfo()[1]
  84. def get_disk_utilization(self):
  85. '''Always ``0``.
  86. .. seealso:
  87. :py:meth:`qubes.vm.qubesvm.QubesVM.get_disk_utilization`
  88. '''
  89. return 0
  90. def get_disk_utilization_private_img(self):
  91. '''Always ``0``.
  92. .. seealso:
  93. :py:meth:`qubes.vm.qubesvm.QubesVM.get_disk_utilization_private_img`
  94. '''
  95. return 0
  96. def get_private_img_sz(self):
  97. '''Always ``0``.
  98. .. seealso:
  99. :py:meth:`qubes.vm.qubesvm.QubesVM.get_private_img_sz`
  100. '''
  101. return 0
  102. def verify_files(self):
  103. '''Always :py:obj:`True`
  104. .. seealso:
  105. :py:meth:`qubes.vm.qubesvm.QubesVM.verify_files`
  106. '''
  107. return True
  108. def start(self, **kwargs):
  109. '''Always raises an exception.
  110. .. seealso:
  111. :py:meth:`qubes.vm.qubesvm.QubesVM.start`
  112. ''' # pylint: disable=unused-argument
  113. raise qubes.exc.QubesVMError(self, 'Cannot start Dom0 fake domain!')
  114. def suspend(self):
  115. '''Does nothing.
  116. .. seealso:
  117. :py:meth:`qubes.vm.qubesvm.QubesVM.suspend`
  118. '''
  119. # XXX shouldn't we spew an exception?
  120. return
  121. # def __init__(self, **kwargs):
  122. # super(QubesAdminVm, self).__init__(qid=0, name="dom0", netid=0,
  123. # dir_path=None,
  124. # private_img = None,
  125. # template = None,
  126. # maxmem = 0,
  127. # vcpus = 0,
  128. # label = defaults["template_label"],
  129. # **kwargs)