diff --git a/qubes/vm/appvm.py b/qubes/vm/appvm.py index 70a1e753..5f9b220c 100644 --- a/qubes/vm/appvm.py +++ b/qubes/vm/appvm.py @@ -86,16 +86,7 @@ class AppVM(qubes.vm.qubesvm.QubesVM): for name, conf in self.volume_config.items(): tpl_volume = template.volumes[name] - conf['size'] = tpl_volume.size - conf['pool'] = tpl_volume.pool - - has_source = ('source' in conf and conf['source'] is not None) - is_snapshot = 'snap_on_start' in conf and conf['snap_on_start'] - if is_snapshot and not has_source: - if tpl_volume.source is not None: - conf['source'] = tpl_volume.source - else: - conf['source'] = tpl_volume.vid + self.config_volume_from_source(conf, tpl_volume) for name, config in template.volume_config.items(): # in case the template vm has more volumes add them to own diff --git a/qubes/vm/dispvm.py b/qubes/vm/dispvm.py index dd660b55..6ae47225 100644 --- a/qubes/vm/dispvm.py +++ b/qubes/vm/dispvm.py @@ -84,17 +84,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM): for name, conf in self.volume_config.items(): tpl_volume = template.volumes[name] - - conf['size'] = tpl_volume.size - conf['pool'] = tpl_volume.pool - - has_source = ('source' in conf and conf['source'] is not None) - is_snapshot = 'snap_on_start' in conf and conf['snap_on_start'] - if is_snapshot and not has_source: - if tpl_volume.source is not None: - conf['source'] = tpl_volume.source - else: - conf['source'] = tpl_volume.vid + self.config_volume_from_source(conf, tpl_volume) for name, config in template.volume_config.items(): # in case the template vm has more volumes add them to own diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index eb3b1058..437b8805 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1762,6 +1762,24 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # helper methods # + @staticmethod + def config_volume_from_source(volume_config, source): + '''Adjust storage volume config to use given volume as a source''' + + volume_config['size'] = source.size + volume_config['pool'] = source.pool + + has_source = ( + 'source' in volume_config and volume_config['source'] is not None) + is_snapshot = 'snap_on_start' in volume_config and volume_config[ + 'snap_on_start'] + if is_snapshot and not has_source: + if source.source is not None: + volume_config['source'] = source.source + else: + volume_config['source'] = source.vid + return volume_config + def relative_path(self, path): '''Return path relative to py:attr:`dir_path`.