templatevm.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 library is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU Lesser General Public
  10. # License as published by the Free Software Foundation; either
  11. # version 2.1 of the License, or (at your option) any later version.
  12. #
  13. # This library 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 GNU
  16. # Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public
  19. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  20. #
  21. ''' This module contains the TemplateVM implementation '''
  22. import warnings
  23. import qubes
  24. import qubes.config
  25. import qubes.vm.qubesvm
  26. import qubes.vm.mix.net
  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. netvm = qubes.VMProperty('netvm', load_stage=4, allow_none=True,
  47. default=None,
  48. # pylint: disable=protected-access
  49. setter=qubes.vm.qubesvm.QubesVM.netvm._setter,
  50. doc='VM that provides network connection to this domain. When '
  51. '`None`, machine is disconnected.')
  52. def __init__(self, *args, **kwargs):
  53. assert 'template' not in kwargs, "A TemplateVM can not have a template"
  54. self.volume_config = {
  55. 'root': {
  56. 'name': 'root',
  57. 'snap_on_start': False,
  58. 'save_on_stop': True,
  59. 'rw': True,
  60. 'source': None,
  61. 'size': defaults['root_img_size'],
  62. },
  63. 'private': {
  64. 'name': 'private',
  65. 'snap_on_start': False,
  66. 'save_on_stop': True,
  67. 'rw': True,
  68. 'source': None,
  69. 'size': defaults['private_img_size'],
  70. 'revisions_to_keep': 0,
  71. },
  72. 'volatile': {
  73. 'name': 'volatile',
  74. 'size': defaults['root_img_size'],
  75. 'snap_on_start': False,
  76. 'save_on_stop': False,
  77. 'rw': True,
  78. },
  79. 'kernel': {
  80. 'name': 'kernel',
  81. 'snap_on_start': False,
  82. 'save_on_stop': False,
  83. 'rw': False
  84. }
  85. }
  86. super(TemplateVM, self).__init__(*args, **kwargs)