templatevm.py 1.2 KB

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