templatevm.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. import qubes.vm.mix.net
  28. from qubes.config import defaults
  29. from qubes.vm.qubesvm import QubesVM
  30. class TemplateVM(QubesVM):
  31. '''Template for AppVM'''
  32. dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
  33. @property
  34. def rootcow_img(self):
  35. '''COW image'''
  36. warnings.warn("rootcow_img is deprecated, use "
  37. "volumes['root'].path_origin", DeprecationWarning)
  38. return self.volumes['root'].path_cow
  39. @property
  40. def appvms(self):
  41. ''' Returns a generator containing all domains based on the current
  42. TemplateVM.
  43. '''
  44. for vm in self.app.domains:
  45. if hasattr(vm, 'template') and vm.template is self:
  46. yield vm
  47. netvm = qubes.VMProperty('netvm', load_stage=4, allow_none=True,
  48. default=None,
  49. # pylint: disable=protected-access
  50. setter=qubes.vm.qubesvm.QubesVM.netvm._setter,
  51. doc='VM that provides network connection to this domain. When '
  52. '`None`, machine is disconnected.')
  53. def __init__(self, *args, **kwargs):
  54. assert 'template' not in kwargs, "A TemplateVM can not have a template"
  55. self.volume_config = {
  56. 'root': {
  57. 'name': 'root',
  58. 'snap_on_start': False,
  59. 'save_on_stop': True,
  60. 'rw': True,
  61. 'source': None,
  62. 'size': defaults['root_img_size'],
  63. },
  64. 'private': {
  65. 'name': 'private',
  66. 'snap_on_start': False,
  67. 'save_on_stop': True,
  68. 'rw': True,
  69. 'source': None,
  70. 'size': defaults['private_img_size'],
  71. 'revisions_to_keep': 0,
  72. },
  73. 'volatile': {
  74. 'name': 'volatile',
  75. 'size': defaults['root_img_size'],
  76. 'snap_on_start': False,
  77. 'save_on_stop': False,
  78. 'rw': True,
  79. },
  80. 'kernel': {
  81. 'name': 'kernel',
  82. 'snap_on_start': False,
  83. 'save_on_stop': False,
  84. 'rw': False
  85. }
  86. }
  87. super(TemplateVM, self).__init__(*args, **kwargs)