QubesVm save the name of the storage pool used

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2015-11-07 19:32:38 +01:00
parent d1685a13df
commit 78891dd70f
4 changed files with 13 additions and 9 deletions

View File

@ -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")

View File

@ -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']

View File

@ -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)

View File

@ -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)