templatevm.py 3.4 KB

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