templatevm.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2014-2016 Wojtek Porczyk <woju@invisiblethingslab.com>
  7. # Copyright (C) 2016 Marek Marczykowski <marmarek@invisiblethingslab.com>)
  8. # Copyright (C) 2016 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. ''' This module contains the TemplateVM implementation '''
  25. import warnings
  26. import qubes
  27. import qubes.config
  28. import qubes.vm.qubesvm
  29. from qubes.config import defaults
  30. from qubes.vm.qubesvm import QubesVM
  31. class TemplateVM(QubesVM):
  32. '''Template for AppVM'''
  33. dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
  34. @property
  35. def rootcow_img(self):
  36. '''COW image'''
  37. warnings.warn("rootcow_img is deprecated, use "
  38. "volumes['root'].path_origin", DeprecationWarning)
  39. return self.volumes['root'].path_cow
  40. @property
  41. def appvms(self):
  42. ''' Returns a generator containing all domains based on the current
  43. TemplateVM.
  44. '''
  45. for vm in self.app.domains:
  46. if hasattr(vm, 'template') and vm.template is self:
  47. yield vm
  48. def __init__(self, *args, **kwargs):
  49. assert 'template' not in kwargs, "A TemplateVM can not have a template"
  50. self.volume_config = {
  51. 'root': {
  52. 'name': 'root',
  53. 'pool': 'default',
  54. 'snap_on_start': False,
  55. 'save_on_stop': True,
  56. 'rw': True,
  57. 'source': None,
  58. 'size': defaults['root_img_size'],
  59. 'internal': True
  60. },
  61. 'private': {
  62. 'name': 'private',
  63. 'pool': 'default',
  64. 'snap_on_start': False,
  65. 'save_on_stop': True,
  66. 'rw': True,
  67. 'source': None,
  68. 'size': defaults['private_img_size'],
  69. 'revisions_to_keep': 0,
  70. 'internal': True
  71. },
  72. 'volatile': {
  73. 'name': 'volatile',
  74. 'pool': 'default',
  75. 'size': defaults['root_img_size'],
  76. 'internal': True,
  77. 'rw': True,
  78. },
  79. 'kernel': {
  80. 'name': 'kernel',
  81. 'pool': 'linux-kernel',
  82. 'snap_on_start': True,
  83. 'internal': True,
  84. 'rw': False
  85. }
  86. }
  87. super(TemplateVM, self).__init__(*args, **kwargs)
  88. def commit_changes(self):
  89. '''Commit changes to template'''
  90. self.log.debug('commit_changes()')
  91. if not self.app.vmm.offline_mode:
  92. assert not self.is_running(), \
  93. 'Attempt to commit changes on running Template VM!'
  94. self.storage.commit()