templatevm.py 1.3 KB

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