templatevm.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.volume_config = {
  26. 'root': {
  27. 'name': 'root',
  28. 'pool': 'default',
  29. 'volume_type': 'origin',
  30. 'size': defaults['root_img_size'],
  31. },
  32. 'private': {
  33. 'name': 'private',
  34. 'pool': 'default',
  35. 'volume_type': 'read-write',
  36. 'size': defaults['private_img_size'],
  37. },
  38. 'volatile': {
  39. 'name': 'volatile',
  40. 'pool': 'default',
  41. 'size': defaults['root_img_size'],
  42. 'volume_type': 'volatile',
  43. },
  44. 'kernel': {
  45. 'name': 'kernel',
  46. 'pool': 'linux-kernel',
  47. 'volume_type': 'read-only',
  48. }
  49. }
  50. super(TemplateVM, self).__init__(*args, **kwargs)
  51. def clone_disk_files(self, src):
  52. super(TemplateVM, self).clone_disk_files(src)
  53. # Create root-cow.img
  54. self.commit_changes()
  55. def commit_changes(self):
  56. '''Commit changes to template'''
  57. self.log.debug('commit_changes()')
  58. if not self.app.vmm.offline_mode:
  59. assert not self.is_running(), \
  60. 'Attempt to commit changes on running Template VM!'
  61. self.storage.commit_template_changes()