Add volume_config to AppVM and TemplateVM

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2016-04-15 13:09:50 +02:00
parent 24193c4308
commit 9d646aabd3
3 changed files with 63 additions and 14 deletions

View File

@ -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

View File

@ -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:

View File

@ -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()