006QubesAdminVm.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2013 Marek Marczykowski <marmarek@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. #
  24. from qubes.qubes import QubesNetVm,register_qubes_vm_class
  25. from qubes.qubes import defaults
  26. from qubes.qubes import QubesException,dry_run,vmm
  27. import psutil
  28. class QubesAdminVm(QubesNetVm):
  29. # In which order load this VM type from qubes.xml
  30. load_order = 10
  31. def get_attrs_config(self):
  32. attrs = super(QubesAdminVm, self).get_attrs_config()
  33. attrs.pop('kernel')
  34. attrs.pop('kernels_dir')
  35. attrs.pop('kernelopts')
  36. attrs.pop('uses_default_kernel')
  37. attrs.pop('uses_default_kernelopts')
  38. return attrs
  39. def __init__(self, **kwargs):
  40. super(QubesAdminVm, self).__init__(qid=0, name="dom0", netid=0,
  41. dir_path=None,
  42. private_img = None,
  43. template = None,
  44. maxmem = 0,
  45. vcpus = 0,
  46. label = defaults["template_label"],
  47. **kwargs)
  48. @property
  49. def xid(self):
  50. return 0
  51. @property
  52. def libvirt_domain(self):
  53. raise ValueError("Dom0 do not have libvirt object")
  54. @property
  55. def type(self):
  56. return "AdminVM"
  57. def is_running(self):
  58. return True
  59. def get_power_state(self):
  60. return "Running"
  61. def get_mem(self):
  62. return psutil.virtual_memory().total/1024
  63. def get_mem_static_max(self):
  64. return vmm.libvirt_conn.getInfo()[1]
  65. def get_cputime(self):
  66. # TODO: measure it somehow
  67. return 0
  68. def get_disk_usage(self, file_or_dir):
  69. return 0
  70. def get_disk_utilization(self):
  71. return 0
  72. def get_disk_utilization_private_img(self):
  73. return 0
  74. def get_private_img_sz(self):
  75. return 0
  76. @property
  77. def ip(self):
  78. return "10.137.0.2"
  79. def start(self, **kwargs):
  80. raise QubesException ("Cannot start Dom0 fake domain!")
  81. def suspend(self):
  82. return
  83. def verify_files(self):
  84. return True
  85. register_qubes_vm_class(QubesAdminVm)