From a017d781747e5d50ea32b0c5351126d978ee65e3 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Fri, 25 Sep 2015 16:50:09 +0200 Subject: [PATCH] Dumb down dir_path property From now, dir_path cannot be set and is calculated from domain's class and name. fixes QubesOS/qubes-issues#1234 --- qubes/vm/adminvm.py | 2 ++ qubes/vm/qubesvm.py | 47 +++++++++++++++++++----------------------- qubes/vm/templatevm.py | 3 +++ 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/qubes/vm/adminvm.py b/qubes/vm/adminvm.py index 0cce6ad3..686b37d5 100644 --- a/qubes/vm/adminvm.py +++ b/qubes/vm/adminvm.py @@ -30,6 +30,8 @@ import qubes.vm.qubesvm class AdminVM(qubes.vm.qubesvm.QubesVM): '''Dom0''' + dir_path = None + netvm = qubes.property('netvm', setter=qubes.property.forbidden, default=None, doc='Dom0 cannot have netvm') diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 90c72ca0..f4bb2e0d 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -124,6 +124,13 @@ def _default_conf_file(self, name=None): class QubesVM(qubes.vm.BaseVM): '''Base functionality of Qubes VM shared between all VMs.''' + # + # per-class properties + # + + #: directory in which domains of this class will reside + dir_path_prefix = qubes.config.system_path['qubes_appvms_dir'] + # # properties loaded from XML # @@ -161,11 +168,6 @@ class QubesVM(qubes.vm.BaseVM): ls_width=36, doc='UUID from libvirt.') - # TODO meaningful default - # TODO setter to ensure absolute/relative path? - dir_path = qubes.property('dir_path', type=str, default=None, - doc='FIXME') - conf_file = qubes.property('conf_file', type=str, default=_default_conf_file, saver=(lambda self, prop, value: self.relative_path(value)), @@ -340,6 +342,16 @@ class QubesVM(qubes.vm.BaseVM): return self._qdb_connection + def _get_dir_path(self, name=None): + return os.path.join( + qubes.config.system_path['qubes_base_dir'], + self.dir_path_prefix, + name if name is not None else self.name) + + dir_path = property(_get_dir_path, + doc='Root directory for files related to this domain') + + # XXX this should go to to AppVM? @property def private_img(self): @@ -391,7 +403,7 @@ class QubesVM(qubes.vm.BaseVM): @property def icon_path(self): - return self.dir_path and os.path.join(self.dir_path, "icon.png") + return os.path.join(self.dir_path, "icon.png") # XXX I don't know what to do with these; probably should be isinstance(...) @@ -609,22 +621,6 @@ class QubesVM(qubes.vm.BaseVM): raise qubes.QubesException('Cannot change name of running domain') - @qubes.events.handler('property-pre-set:dir_path') - def on_property_pre_set_dir_path(self, event, name, newvalue, - oldvalue=None): - # pylint: disable=unused-argument - # TODO not self.is_stopped() would be more appropriate - if self.is_running(): - raise qubes.QubesException( - 'Cannot change dir_path of running domain') - - - @qubes.events.handler('property-set:dir_path') - def on_property_set_dir_path(self, event, name, newvalue, oldvalue=None): - # pylint: disable=unused-argument - self.storage.rename(newvalue, oldvalue) - - @qubes.events.handler('property-set:name') def on_property_set_name(self, event, name, new_name, old_name=None): # pylint: disable=unused-argument @@ -637,9 +633,9 @@ class QubesVM(qubes.vm.BaseVM): self._qdb_connection.close() self._qdb_connection = None - # move: dir_path, conf_file - self.dir_path = self.dir_path.replace( - '/{}/', '/{}/'.format(old_name, new_name)) + self.storage.rename( + self._get_dir_path(new_name), + self._get_dir_path(old_name)) if self.property_is_default('conf_file'): new_conf = os.path.join( @@ -1666,7 +1662,6 @@ class QubesVM(qubes.vm.BaseVM): ''' return os.path.relpath(path, self.dir_path) -# return arg.replace(self.dir_path + '/', '') def create_qdb_entries(self): diff --git a/qubes/vm/templatevm.py b/qubes/vm/templatevm.py index 9be4c34b..6862ff5c 100644 --- a/qubes/vm/templatevm.py +++ b/qubes/vm/templatevm.py @@ -4,11 +4,14 @@ import os.path import qubes +import qubes.config import qubes.vm.qubesvm class TemplateVM(qubes.vm.qubesvm.QubesVM): '''Template for AppVM''' + dir_path_prefix = qubes.config.system_path['qubes_templates_dir'] + @property def rootcow_img(self): '''COW image'''