templatevm.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. import qubes
  4. import qubes.config
  5. import qubes.vm.qubesvm
  6. class TemplateVM(qubes.vm.qubesvm.QubesVM):
  7. '''Template for AppVM'''
  8. dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
  9. @property
  10. def rootcow_img(self):
  11. '''COW image'''
  12. return self.storage.rootcow_img
  13. @property
  14. def appvms(self):
  15. for vm in self.app.domains:
  16. if hasattr(vm, 'template') and vm.template is self:
  17. yield vm
  18. def __init__(self, *args, **kwargs):
  19. super(TemplateVM, self).__init__(*args, **kwargs)
  20. # Some additional checks for template based VM
  21. # TODO find better way
  22. # assert self.root_img is not None, "Missing root_img for standalone VM!"
  23. def clone_disk_files(self, src):
  24. super(TemplateVM, self).clone_disk_files(src)
  25. # Create root-cow.img
  26. self.commit_changes()
  27. def commit_changes(self):
  28. '''Commit changes to template'''
  29. self.log.debug('commit_changes()')
  30. if not self.app.vmm.offline_mode:
  31. assert not self.is_running(), \
  32. 'Attempt to commit changes on running Template VM!'
  33. self.log.info(
  34. 'Commiting template update; COW: {}'.format(self.rootcow_img))
  35. self.storage.commit_template_changes()