Implement changing the template of a DispVM

This commit is contained in:
Demi Marie Obenour 2020-11-20 01:35:13 -05:00
parent 39ef189a93
commit e11f94b496
No known key found for this signature in database
GPG Key ID: 28A45C93B0B5B6E0
2 changed files with 30 additions and 13 deletions

View File

@ -145,14 +145,33 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
''' # pylint: disable=unused-argument ''' # pylint: disable=unused-argument
assert self.template assert self.template
@qubes.events.handler('property-pre-set:template', @qubes.events.handler('property-pre-reset:template')
'property-pre-reset:template') def on_property_pre_reset_template(self, event, name, oldvalue=None):
def on_property_pre_set_template(self, event, name, newvalue=None, '''Forbid deleting template of running VM
''' # pylint: disable=unused-argument,no-self-use
raise qubes.exc.QubesValueError('Cannot unset template')
@qubes.events.handler('property-pre-set:template')
def on_property_pre_set_template(self, event, name, newvalue,
oldvalue=None): oldvalue=None):
''' Disposable VM cannot have template changed ''' '''Forbid changing template of running VM
# pylint: disable=unused-argument ''' # pylint: disable=unused-argument
raise qubes.exc.QubesValueError(self, if not self.is_halted():
'Cannot change template of Disposable VM') raise qubes.exc.QubesVMNotHaltedError(self,
'Cannot change template while qube is running')
@qubes.events.handler('property-set:template')
def on_property_set_template(self, event, name, newvalue, oldvalue=None):
''' Adjust root (and possibly other snap_on_start=True) volume
on template change.
''' # pylint: disable=unused-argument
for volume_name, conf in self.default_volume_config.items():
if conf.get('snap_on_start', False) and \
conf.get('source', None) is None:
config = conf.copy()
self.volume_config[volume_name] = config
self.storage.init_volume(volume_name, config)
@qubes.events.handler('domain-shutdown') @qubes.events.handler('domain-shutdown')
@asyncio.coroutine @asyncio.coroutine

View File

@ -45,14 +45,12 @@ class DVMTemplateMixin(qubes.events.Emitter):
self.__on_pre_set_dvmtemplate( self.__on_pre_set_dvmtemplate(
event, name, False, oldvalue) event, name, False, oldvalue)
@qubes.events.handler('property-pre-set:template') @qubes.events.handler('property-set:template')
def __on_property_pre_set_template(self, event, name, newvalue, def __on_property_set_template(self, event, name, newvalue,
oldvalue=None): oldvalue=None):
# pylint: disable=unused-argument # pylint: disable=unused-argument
if any(self.dispvms): for vm in self.dispvms:
raise qubes.exc.QubesVMInUseError(self, vm.on_property_set_template(event, name, newvalue, oldvalue)
'Cannot change template '
'while there are DispVMs based on this qube')
@property @property
def dispvms(self): def dispvms(self):