adminvm.py 4.4 KB

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