adminvm.py 4.6 KB

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