02QubesTemplateHVm.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/python2
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. # Copyright (C) 2013 Marek Marczykowski <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import os
  24. import os.path
  25. import subprocess
  26. import stat
  27. import sys
  28. import re
  29. from qubes.qubes import QubesHVm,register_qubes_vm_class,xs,xc,dry_run
  30. from qubes.qubes import QubesException,QubesVmCollection
  31. from qubes.qubes import system_path,defaults
  32. class QubesTemplateHVm(QubesHVm):
  33. """
  34. A class that represents an HVM template. A child of QubesHVm.
  35. """
  36. # In which order load this VM type from qubes.xml
  37. load_order = 50
  38. def get_attrs_config(self):
  39. attrs_config = super(QubesTemplateHVm, self).get_attrs_config()
  40. attrs_config['dir_path']['eval'] = 'value if value is not None else os.path.join(system_path["qubes_templates_dir"], self.name)'
  41. attrs_config['label']['default'] = defaults["template_label"]
  42. return attrs_config
  43. def __init__(self, **kwargs):
  44. super(QubesTemplateHVm, self).__init__(**kwargs)
  45. self.appvms = QubesVmCollection()
  46. @property
  47. def type(self):
  48. return "TemplateHVM"
  49. @property
  50. def updateable(self):
  51. return True
  52. def is_template(self):
  53. return True
  54. def is_appvm(self):
  55. return False
  56. @classmethod
  57. def is_template_compatible(cls, template):
  58. return False
  59. def start(self, *args, **kwargs):
  60. for vm in self.appvms.values():
  61. if vm.is_running():
  62. raise QubesException("Cannot start HVM template while VMs based on it are running")
  63. return super(QubesTemplateHVm, self).start(*args, **kwargs)
  64. register_qubes_vm_class(QubesTemplateHVm)