templatevm.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. import warnings
  4. import qubes
  5. import qubes.config
  6. import qubes.vm.qubesvm
  7. from qubes.config import defaults
  8. from qubes.vm.qubesvm import QubesVM
  9. class TemplateVM(QubesVM):
  10. '''Template for AppVM'''
  11. dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
  12. @property
  13. def rootcow_img(self):
  14. '''COW image'''
  15. warnings.warn("rootcow_img is deprecated, use "
  16. "volumes['root'].path_origin", DeprecationWarning)
  17. return self.volumes['root'].path_cow
  18. @property
  19. def appvms(self):
  20. for vm in self.app.domains:
  21. if hasattr(vm, 'template') and vm.template is self:
  22. yield vm
  23. def __init__(self, *args, **kwargs):
  24. assert 'template' not in kwargs, "A TemplateVM can not have a template"
  25. self.volumes = {}
  26. self.volume_config = {
  27. 'root': {
  28. 'name': 'root',
  29. 'pool': 'default',
  30. 'volume_type': 'origin',
  31. 'size': defaults['root_img_size'],
  32. },
  33. 'private': {
  34. 'name': 'private',
  35. 'pool': 'default',
  36. 'volume_type': 'read-write',
  37. 'size': defaults['private_img_size'],
  38. },
  39. 'volatile': {
  40. 'name': 'volatile',
  41. 'pool': 'default',
  42. 'size': defaults['root_img_size'],
  43. 'volume_type': 'volatile',
  44. },
  45. 'kernel': {
  46. 'name': 'kernel',
  47. 'pool': 'linux-kernel',
  48. 'volume_type': 'read-only',
  49. }
  50. }
  51. super(TemplateVM, self).__init__(*args, **kwargs)
  52. def clone_disk_files(self, src):
  53. super(TemplateVM, self).clone_disk_files(src)
  54. # Create root-cow.img
  55. self.commit_changes()
  56. def commit_changes(self):
  57. '''Commit changes to template'''
  58. self.log.debug('commit_changes()')
  59. if not self.app.vmm.offline_mode:
  60. assert not self.is_running(), \
  61. 'Attempt to commit changes on running Template VM!'
  62. self.storage.commit_template_changes()