adminvm.py 4.8 KB

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