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
This commit is contained in:
parent
12329e7b35
commit
a017d78174
@ -30,6 +30,8 @@ import qubes.vm.qubesvm
|
|||||||
class AdminVM(qubes.vm.qubesvm.QubesVM):
|
class AdminVM(qubes.vm.qubesvm.QubesVM):
|
||||||
'''Dom0'''
|
'''Dom0'''
|
||||||
|
|
||||||
|
dir_path = None
|
||||||
|
|
||||||
netvm = qubes.property('netvm', setter=qubes.property.forbidden,
|
netvm = qubes.property('netvm', setter=qubes.property.forbidden,
|
||||||
default=None,
|
default=None,
|
||||||
doc='Dom0 cannot have netvm')
|
doc='Dom0 cannot have netvm')
|
||||||
|
@ -124,6 +124,13 @@ def _default_conf_file(self, name=None):
|
|||||||
class QubesVM(qubes.vm.BaseVM):
|
class QubesVM(qubes.vm.BaseVM):
|
||||||
'''Base functionality of Qubes VM shared between all VMs.'''
|
'''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
|
# properties loaded from XML
|
||||||
#
|
#
|
||||||
@ -161,11 +168,6 @@ class QubesVM(qubes.vm.BaseVM):
|
|||||||
ls_width=36,
|
ls_width=36,
|
||||||
doc='UUID from libvirt.')
|
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,
|
conf_file = qubes.property('conf_file', type=str,
|
||||||
default=_default_conf_file,
|
default=_default_conf_file,
|
||||||
saver=(lambda self, prop, value: self.relative_path(value)),
|
saver=(lambda self, prop, value: self.relative_path(value)),
|
||||||
@ -340,6 +342,16 @@ class QubesVM(qubes.vm.BaseVM):
|
|||||||
return self._qdb_connection
|
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?
|
# XXX this should go to to AppVM?
|
||||||
@property
|
@property
|
||||||
def private_img(self):
|
def private_img(self):
|
||||||
@ -391,7 +403,7 @@ class QubesVM(qubes.vm.BaseVM):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def icon_path(self):
|
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(...)
|
# 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')
|
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')
|
@qubes.events.handler('property-set:name')
|
||||||
def on_property_set_name(self, event, name, new_name, old_name=None):
|
def on_property_set_name(self, event, name, new_name, old_name=None):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -637,9 +633,9 @@ class QubesVM(qubes.vm.BaseVM):
|
|||||||
self._qdb_connection.close()
|
self._qdb_connection.close()
|
||||||
self._qdb_connection = None
|
self._qdb_connection = None
|
||||||
|
|
||||||
# move: dir_path, conf_file
|
self.storage.rename(
|
||||||
self.dir_path = self.dir_path.replace(
|
self._get_dir_path(new_name),
|
||||||
'/{}/', '/{}/'.format(old_name, new_name))
|
self._get_dir_path(old_name))
|
||||||
|
|
||||||
if self.property_is_default('conf_file'):
|
if self.property_is_default('conf_file'):
|
||||||
new_conf = os.path.join(
|
new_conf = os.path.join(
|
||||||
@ -1666,7 +1662,6 @@ class QubesVM(qubes.vm.BaseVM):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
return os.path.relpath(path, self.dir_path)
|
return os.path.relpath(path, self.dir_path)
|
||||||
# return arg.replace(self.dir_path + '/', '')
|
|
||||||
|
|
||||||
|
|
||||||
def create_qdb_entries(self):
|
def create_qdb_entries(self):
|
||||||
|
@ -4,11 +4,14 @@
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import qubes
|
import qubes
|
||||||
|
import qubes.config
|
||||||
import qubes.vm.qubesvm
|
import qubes.vm.qubesvm
|
||||||
|
|
||||||
class TemplateVM(qubes.vm.qubesvm.QubesVM):
|
class TemplateVM(qubes.vm.qubesvm.QubesVM):
|
||||||
'''Template for AppVM'''
|
'''Template for AppVM'''
|
||||||
|
|
||||||
|
dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rootcow_img(self):
|
def rootcow_img(self):
|
||||||
'''COW image'''
|
'''COW image'''
|
||||||
|
Loading…
Reference in New Issue
Block a user