From 9d646aabd326bc30626b5ee64ef02fd229b57ee1 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Fri, 15 Apr 2016 13:09:50 +0200 Subject: [PATCH] Add volume_config to AppVM and TemplateVM --- qubes/vm/appvm.py | 38 +++++++++++++++++++++++++++++++++----- qubes/vm/qubesvm.py | 1 - qubes/vm/templatevm.py | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index aa2e3966..d310ca99 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -3,16 +3,44 @@ import qubes.events import qubes.vm.qubesvm +from qubes.config import defaults + class AppVM(qubes.vm.qubesvm.QubesVM): '''Application VM''' - template = qubes.VMProperty('template', load_stage=4, - vmclass=qubes.vm.templatevm.TemplateVM, - ls_width=31, - doc='Template, on which this AppVM is based.') + template = qubes.VMProperty('template', + load_stage=4, + vmclass=qubes.vm.templatevm.TemplateVM, + ls_width=31, + doc='Template, on which this AppVM is based.') def __init__(self, *args, **kwargs): + self.volumes = {} + self.volume_config = { + 'root': { + 'name': 'root', + 'pool': 'default', + 'volume_type': 'snapshot', + }, + 'private': { + 'name': 'private', + 'pool': 'default', + 'volume_type': 'read-write', + 'size': defaults['private_img_size'], + }, + 'volatile': { + 'name': 'volatile', + 'pool': 'default', + 'volume_type': 'volatile', + 'size': defaults['root_img_size'], + }, + 'kernel': { + 'name': 'kernel', + 'pool': 'linux-kernel', + 'volume_type': 'read-only', + } + } super(AppVM, self).__init__(*args, **kwargs) @qubes.events.handler('domain-load') @@ -20,4 +48,4 @@ class AppVM(qubes.vm.qubesvm.QubesVM): # pylint: disable=unused-argument # Some additional checks for template based VM assert self.template - #self.template.appvms.add(self) # XXX + # self.template.appvms.add(self) # XXX diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 27ec98d7..9aef6f71 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -464,7 +464,6 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): self.features['check-updates'] = None # will be initialized after loading all the properties - self.storage = None # fire hooks if xml is None: diff --git a/qubes/vm/templatevm.py b/qubes/vm/templatevm.py index f0c7fe2f..7eadc134 100644 --- a/qubes/vm/templatevm.py +++ b/qubes/vm/templatevm.py @@ -4,6 +4,8 @@ import qubes import qubes.config import qubes.vm.qubesvm +from qubes.config import defaults + class TemplateVM(qubes.vm.qubesvm.QubesVM): '''Template for AppVM''' @@ -23,20 +25,40 @@ class TemplateVM(qubes.vm.qubesvm.QubesVM): def __init__(self, *args, **kwargs): assert 'template' not in kwargs, "A TemplateVM can not have a template" + self.volumes = {} + self.volume_config = { + 'root': { + 'name': 'root', + 'pool': 'default', + 'volume_type': 'origin', + 'size': defaults['root_img_size'], + }, + 'private': { + 'name': 'private', + 'pool': 'default', + 'volume_type': 'read-write', + 'size': defaults['private_img_size'], + }, + 'volatile': { + 'name': 'volatile', + 'pool': 'default', + 'size': defaults['root_img_size'], + 'volume_type': 'volatile', + }, + 'kernel': { + 'name': 'kernel', + 'pool': 'linux-kernel', + 'volume_type': 'read-only', + } + } super(TemplateVM, self).__init__(*args, **kwargs) - # Some additional checks for template based VM - # TODO find better way -# assert self.root_img is not None, "Missing root_img for standalone VM!" - - def clone_disk_files(self, src): super(TemplateVM, self).clone_disk_files(src) # Create root-cow.img self.commit_changes() - def commit_changes(self): '''Commit changes to template''' self.log.debug('commit_changes()') @@ -45,6 +67,6 @@ class TemplateVM(qubes.vm.qubesvm.QubesVM): assert not self.is_running(), \ 'Attempt to commit changes on running Template VM!' - self.log.info( - 'Commiting template update; COW: {}'.format(self.rootcow_img)) + self.log.info('Commiting template update; COW: {}'.format( + self.rootcow_img)) self.storage.commit_template_changes()