vm: reduce code duplication
Move inheriting volume from template to a helper function. No functional change. QubesOS/qubes-issues#2256
This commit is contained in:
parent
28737d16ce
commit
63c23c835b
@ -86,16 +86,7 @@ class AppVM(qubes.vm.qubesvm.QubesVM):
|
|||||||
for name, conf in self.volume_config.items():
|
for name, conf in self.volume_config.items():
|
||||||
tpl_volume = template.volumes[name]
|
tpl_volume = template.volumes[name]
|
||||||
|
|
||||||
conf['size'] = tpl_volume.size
|
self.config_volume_from_source(conf, tpl_volume)
|
||||||
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
|
|
||||||
|
|
||||||
for name, config in template.volume_config.items():
|
for name, config in template.volume_config.items():
|
||||||
# in case the template vm has more volumes add them to own
|
# in case the template vm has more volumes add them to own
|
||||||
|
@ -84,17 +84,7 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
|
|||||||
|
|
||||||
for name, conf in self.volume_config.items():
|
for name, conf in self.volume_config.items():
|
||||||
tpl_volume = template.volumes[name]
|
tpl_volume = template.volumes[name]
|
||||||
|
self.config_volume_from_source(conf, tpl_volume)
|
||||||
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
|
|
||||||
|
|
||||||
for name, config in template.volume_config.items():
|
for name, config in template.volume_config.items():
|
||||||
# in case the template vm has more volumes add them to own
|
# in case the template vm has more volumes add them to own
|
||||||
|
@ -1762,6 +1762,24 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
|||||||
# helper methods
|
# 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):
|
def relative_path(self, path):
|
||||||
'''Return path relative to py:attr:`dir_path`.
|
'''Return path relative to py:attr:`dir_path`.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user