003QubesTemplateVm.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import os
  25. import sys
  26. from qubes.qubes import (
  27. defaults,
  28. dry_run,
  29. register_qubes_vm_class,
  30. system_path,
  31. vmm,
  32. QubesResizableVmWithResize2fs,
  33. QubesVmCollection,
  34. )
  35. class QubesTemplateVm(QubesResizableVmWithResize2fs):
  36. """
  37. A class that represents an TemplateVM. A child of QubesVm.
  38. """
  39. # In which order load this VM type from qubes.xml
  40. load_order = 50
  41. def get_attrs_config(self):
  42. attrs_config = super(QubesTemplateVm, self).get_attrs_config()
  43. attrs_config['dir_path']['func'] = \
  44. lambda value: value if value is not None else \
  45. os.path.join(system_path["qubes_templates_dir"], self.name)
  46. attrs_config['label']['default'] = defaults["template_label"]
  47. return attrs_config
  48. def __init__(self, **kwargs):
  49. super(QubesTemplateVm, self).__init__(**kwargs)
  50. self.appvms = QubesVmCollection()
  51. @property
  52. def type(self):
  53. return "TemplateVM"
  54. @property
  55. def updateable(self):
  56. return True
  57. def is_template(self):
  58. return True
  59. def get_firewall_defaults(self):
  60. return { "rules": list(), "allow": False, "allowDns": False, "allowIcmp": False, "allowYumProxy": True }
  61. @property
  62. def rootcow_img(self):
  63. return self.storage.rootcow_img
  64. def clone_disk_files(self, src_vm, verbose):
  65. if dry_run:
  66. return
  67. super(QubesTemplateVm, self).clone_disk_files(src_vm=src_vm, verbose=verbose)
  68. # Create root-cow.img
  69. self.commit_changes(verbose=verbose)
  70. def commit_changes (self, verbose = False):
  71. self.log.debug('commit_changes()')
  72. if not vmm.offline_mode:
  73. assert not self.is_running(), "Attempt to commit changes on running Template VM!"
  74. if verbose:
  75. print >> sys.stderr, "--> Commiting template updates... COW: {0}...".format (self.rootcow_img)
  76. if dry_run:
  77. return
  78. self.storage.commit_template_changes()
  79. register_qubes_vm_class(QubesTemplateVm)