diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index f8fdd76c..615652db 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -40,12 +40,12 @@ import signal from qubes import qmemman from qubes import qmemman_algo import libvirt -import warnings from qubes.qubes import dry_run,vmm from qubes.qubes import register_qubes_vm_class from qubes.qubes import QubesVmCollection,QubesException,QubesHost,QubesVmLabels from qubes.qubes import defaults,system_path,vm_files,qubes_max_qid +from qubes.storage import get_pool qmemman_present = False try: @@ -109,6 +109,7 @@ class QubesVm(object): "name": { "order": 1 }, "uuid": { "order": 0, "eval": 'uuid.UUID(value) if value else None' }, "dir_path": { "default": None, "order": 2 }, + "pool_name": { "default":"default" }, "conf_file": { "func": lambda value: self.absolute_path(value, self.name + ".conf"), @@ -198,7 +199,7 @@ class QubesVm(object): 'kernelopts', 'services', 'installed_by_rpm',\ 'uses_default_netvm', 'include_in_backups', 'debug',\ 'qrexec_timeout', 'autostart', 'uses_default_dispvm_netvm', - 'backup_content', 'backup_size', 'backup_path' ]: + 'backup_content', 'backup_size', 'backup_path', 'pool_name' ]: attrs[prop]['save'] = lambda prop=prop: str(getattr(self, prop)) # Simple paths for prop in ['conf_file', 'firewall_conf']: @@ -345,7 +346,7 @@ class QubesVm(object): self.services['qubes-update-check'] = False # Initialize VM image storage class - self.storage = defaults["storage_class"](self) + self.storage = get_pool(self.pool_name, self).getStorage() if hasattr(self, 'kernels_dir'): modules_path = os.path.join(self.kernels_dir, "modules.img") diff --git a/core/storage/__init__.py b/core/storage/__init__.py index aabb2f65..4636dc47 100644 --- a/core/storage/__init__.py +++ b/core/storage/__init__.py @@ -239,11 +239,10 @@ def load(string): return getattr(module, klass) -def get_pool(vm): +def get_pool(name, vm): """ Instantiates the storage for the specified vm """ config = _get_storage_config_parser() - name = vm.storage_pool klass = _get_pool_klass(name, config) keys = [k for k in config.options(name) if k != 'type' and k != 'class'] diff --git a/core/storage/xen.py b/core/storage/xen.py index 9c1a75cc..01ed0277 100644 --- a/core/storage/xen.py +++ b/core/storage/xen.py @@ -28,7 +28,7 @@ import re import subprocess import sys -from qubes.qubes import QubesException, vm_files +from qubes.qubes import QubesException, defaults, vm_files from qubes.storage import Pool, QubesVmStorage @@ -252,4 +252,8 @@ class XenStorage(QubesVmStorage): class XenPool(Pool): - pass + def __init__(self, vm): + self.vm = vm + + def getStorage(self): + return defaults['storage_class'](self.vm) diff --git a/tests/storage.py b/tests/storage.py index e3fb4b29..3115535d 100644 --- a/tests/storage.py +++ b/tests/storage.py @@ -30,7 +30,7 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase): """ Dumps storage instance to a storage string """ vmname = self.make_vm_name('appvm') template = self.qc.get_default_template() - storage = self.qc.add_new_vm('QubesAppVm', name=vmname, pool='default', + storage = self.qc.add_new_vm('QubesAppVm', name=vmname, pool_name='default', template=template).storage result = qubes.storage.dump(storage) expected = 'qubes.storage.xen.XenStorage' @@ -68,5 +68,5 @@ class TC_01_Storage(SystemTestsMixin, QubesTestCase): vmname = self.make_vm_name('appvm') template = self.qc.get_default_template() vm = self.qc.add_new_vm('QubesAppVm', name=vmname, template=template, - pool='default') + pool_name='default') self.assertIsInstance(vm.storage, XenStorage)