adminvm.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.vm.qubesvm
  27. class AdminVM(qubes.vm.qubesvm.QubesVM):
  28. '''Dom0'''
  29. dir_path = None
  30. netvm = qubes.property('netvm', setter=qubes.property.forbidden,
  31. default=None,
  32. doc='Dom0 cannot have netvm')
  33. kernel = qubes.property('netvm', setter=qubes.property.forbidden,
  34. default=None,
  35. doc='There are other ways to set kernel for Dom0.')
  36. @property
  37. def xid(self):
  38. '''Always ``0``.
  39. .. seealso:
  40. :py:attr:`qubes.vm.qubesvm.QubesVM.xid`
  41. '''
  42. return 0
  43. @property
  44. def libvirt_domain(self):
  45. '''Always :py:obj:`None`.
  46. .. seealso:
  47. :py:attr:`qubes.vm.qubesvm.QubesVM.libvirt_domain`
  48. '''
  49. return None
  50. @property
  51. def kernels_dir(self):
  52. '''Always :py:obj:`None`.
  53. .. seealso:
  54. :py:attr:`qubes.vm.qubesvm.QubesVM.kernels_dir`
  55. '''
  56. return None
  57. # XXX probably unneeded, will return None as we don't have netvm
  58. # @property
  59. # def ip(self):
  60. # return "10.137.0.2"
  61. def is_running(self):
  62. '''Always :py:obj:`True`.
  63. .. seealso:
  64. :py:meth:`qubes.vm.qubesvm.QubesVM.is_running`
  65. '''
  66. return True
  67. def get_power_state(self):
  68. '''Always ``'Running'``.
  69. .. seealso:
  70. :py:meth:`qubes.vm.qubesvm.QubesVM.get_power_state`
  71. '''
  72. return 'Running'
  73. def get_mem(self):
  74. '''Get current memory usage of Dom0.
  75. Unit is KiB.
  76. .. seealso:
  77. :py:meth:`qubes.vm.qubesvm.QubesVM.get_mem`
  78. '''
  79. #return psutil.virtual_memory().total/1024
  80. for line in open('/proc/meminfo'):
  81. if line.startswith('MemTotal:'):
  82. return int(line.split(':')[1].strip().split()[0])
  83. raise NotImplementedError()
  84. def get_mem_static_max(self):
  85. '''Get maximum memory available to Dom0.
  86. .. seealso:
  87. :py:meth:`qubes.vm.qubesvm.QubesVM.get_mem_static_max`
  88. '''
  89. return self.app.vmm.libvirt_conn.getInfo()[1]
  90. def get_disk_utilization(self):
  91. '''Always ``0``.
  92. .. seealso:
  93. :py:meth:`qubes.vm.qubesvm.QubesVM.get_disk_utilization`
  94. '''
  95. return 0
  96. def get_disk_utilization_private_img(self):
  97. '''Always ``0``.
  98. .. seealso:
  99. :py:meth:`qubes.vm.qubesvm.QubesVM.get_disk_utilization_private_img`
  100. '''
  101. return 0
  102. def get_private_img_sz(self):
  103. '''Always ``0``.
  104. .. seealso:
  105. :py:meth:`qubes.vm.qubesvm.QubesVM.get_private_img_sz`
  106. '''
  107. return 0
  108. def verify_files(self):
  109. '''Always :py:obj:`True`
  110. .. seealso:
  111. :py:meth:`qubes.vm.qubesvm.QubesVM.verify_files`
  112. '''
  113. return True
  114. def start(self, **kwargs):
  115. '''Always raises an exception.
  116. .. seealso:
  117. :py:meth:`qubes.vm.qubesvm.QubesVM.start`
  118. ''' # pylint: disable=unused-argument
  119. raise qubes.QubesException('Cannot start Dom0 fake domain!')
  120. def suspend(self):
  121. '''Does nothing.
  122. .. seealso:
  123. :py:meth:`qubes.vm.qubesvm.QubesVM.suspend`
  124. '''
  125. # XXX shouldn't we spew an exception?
  126. return
  127. # def __init__(self, **kwargs):
  128. # super(QubesAdminVm, self).__init__(qid=0, name="dom0", netid=0,
  129. # dir_path=None,
  130. # private_img = None,
  131. # template = None,
  132. # maxmem = 0,
  133. # vcpus = 0,
  134. # label = defaults["template_label"],
  135. # **kwargs)