storage: improve/fix handling extra volumes
Just calling pool.init_volume isn't enough - a lot of code depends on additional data loaded into vm.storage object. Provide a convenient wrapper for this. At the same time, fix loading extra volumes from qubes.xml - don't fail on volume not mentioned in initial vm.volume_config. QubesOS/qubes-issues#2256
This commit is contained in:
parent
4323651afb
commit
ab9d7fbb76
@ -194,14 +194,23 @@ class Storage(object):
|
|||||||
|
|
||||||
if hasattr(vm, 'volume_config'):
|
if hasattr(vm, 'volume_config'):
|
||||||
for name, conf in self.vm.volume_config.items():
|
for name, conf in self.vm.volume_config.items():
|
||||||
assert 'pool' in conf, "Pool missing in volume_config" % str(
|
|
||||||
conf)
|
|
||||||
if 'volume_type' in conf:
|
if 'volume_type' in conf:
|
||||||
conf = self._migrate_config(conf)
|
conf = self._migrate_config(conf)
|
||||||
|
|
||||||
pool = self.vm.app.get_pool(conf['pool'])
|
self.init_volume(name, conf)
|
||||||
self.vm.volumes[name] = pool.init_volume(self.vm, conf)
|
|
||||||
self.pools[name] = pool
|
def init_volume(self, name, volume_config):
|
||||||
|
''' Initialize Volume instance attached to this domain '''
|
||||||
|
assert 'pool' in volume_config, "Pool missing in volume_config" % str(
|
||||||
|
volume_config)
|
||||||
|
|
||||||
|
if 'name' not in volume_config:
|
||||||
|
volume_config['name'] = name
|
||||||
|
pool = self.vm.app.get_pool(volume_config['pool'])
|
||||||
|
volume = pool.init_volume(self.vm, volume_config)
|
||||||
|
self.vm.volumes[name] = volume
|
||||||
|
self.pools[name] = pool
|
||||||
|
return volume
|
||||||
|
|
||||||
def _migrate_config(self, conf):
|
def _migrate_config(self, conf):
|
||||||
''' Migrates from the old config style to new
|
''' Migrates from the old config style to new
|
||||||
|
@ -427,14 +427,19 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
|||||||
for key, value in node.items():
|
for key, value in node.items():
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
if value == 'True':
|
if value == 'True':
|
||||||
self.volume_config[name][key] = True
|
value = True
|
||||||
else:
|
try:
|
||||||
self.volume_config[name][key] = value
|
self.volume_config[name][key] = value
|
||||||
|
except KeyError:
|
||||||
|
self.volume_config[name] = {key: value}
|
||||||
|
|
||||||
for name, conf in volume_config.items():
|
for name, conf in volume_config.items():
|
||||||
for key, value in conf.items():
|
for key, value in conf.items():
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
self.volume_config[name][key] = value
|
try:
|
||||||
|
self.volume_config[name][key] = value
|
||||||
|
except KeyError:
|
||||||
|
self.volume_config[name] = {key: value}
|
||||||
|
|
||||||
elif volume_config:
|
elif volume_config:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
|
Loading…
Reference in New Issue
Block a user