From 04f86c705937ef733ecbdc29ebcdcfcf801faea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 27 Mar 2014 17:15:15 +0100 Subject: [PATCH] core: use functions instead of evals for storing attributes to qubes.xml --- core-modules/000QubesVm.py | 27 ++++++++++++++++----------- core-modules/005QubesNetVm.py | 4 +++- core-modules/006QubesProxyVm.py | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/core-modules/000QubesVm.py b/core-modules/000QubesVm.py index 64a3a5df..75b8dc46 100644 --- a/core-modules/000QubesVm.py +++ b/core-modules/000QubesVm.py @@ -185,24 +185,29 @@ class QubesVm(object): 'default_user', 'qrexec_timeout', 'autostart', 'default_user', 'qrexec_timeout', 'backup_content', 'backup_size', 'backup_path' ]: - attrs[prop]['save'] = 'str(self.%s)' % prop + attrs[prop]['save'] = lambda prop=prop: str(getattr(self, prop)) # Simple paths for prop in ['conf_file', 'root_img', 'volatile_img', 'private_img']: - attrs[prop]['save'] = 'self.relative_path(self.%s)' % prop - attrs[prop]['save_skip'] = 'self.%s is None' % prop + attrs[prop]['save'] = \ + lambda prop=prop: self.relative_path(getattr(self, prop)) + attrs[prop]['save_skip'] = \ + lambda prop=prop: getattr(self, prop) is None - attrs['mac']['save'] = 'str(self._mac)' - attrs['mac']['save_skip'] = 'self._mac is None' + attrs['mac']['save'] = lambda: str(self._mac) + attrs['mac']['save_skip'] = lambda: self._mac is None - attrs['backup_timestamp']['save'] = 'self.backup_timestamp.strftime("%s")' - attrs['backup_timestamp']['save_skip'] = 'self.backup_timestamp is ' \ - 'None' + attrs['backup_timestamp']['save'] = \ + lambda: self.backup_timestamp.strftime("%s") + attrs['backup_timestamp']['save_skip'] = \ + lambda: self.backup_timestamp is None - attrs['netvm']['save'] = 'str(self.netvm.qid) if self.netvm is not None else "none"' + attrs['netvm']['save'] = \ + lambda: str(self.netvm.qid) if self.netvm is not None else "none" attrs['netvm']['save_attr'] = "netvm_qid" - attrs['template']['save'] = 'str(self.template.qid) if self.template else "none"' + attrs['template']['save'] = \ + lambda: str(self.template.qid) if self.template else "none" attrs['template']['save_attr'] = "template_qid" - attrs['label']['save'] = 'self.label.name' + attrs['label']['save'] = lambda: self.label.name # fire hooks for hook in self.hooks_get_attrs_config: diff --git a/core-modules/005QubesNetVm.py b/core-modules/005QubesNetVm.py index 4691fe06..43840333 100644 --- a/core-modules/005QubesNetVm.py +++ b/core-modules/005QubesNetVm.py @@ -45,7 +45,9 @@ class QubesNetVm(QubesVm): attrs_config['memory']['default'] = 200 # New attributes - attrs_config['netid'] = { 'save': 'str(self.netid)', 'order': 30, + attrs_config['netid'] = { + 'save': lambda: str(self.netid), + 'order': 30, 'func': lambda value: value if value is not None else self._collection.get_new_unused_netid() } attrs_config['netprefix'] = { diff --git a/core-modules/006QubesProxyVm.py b/core-modules/006QubesProxyVm.py index 398fa67e..fe956914 100644 --- a/core-modules/006QubesProxyVm.py +++ b/core-modules/006QubesProxyVm.py @@ -39,7 +39,7 @@ class QubesProxyVm(QubesNetVm): attrs_config['uses_default_netvm']['func'] = lambda x: False # Save netvm prop again attrs_config['netvm']['save'] = \ - lambda x: str(self.netvm.qid) if self.netvm is not None else "none" + lambda: str(self.netvm.qid) if self.netvm is not None else "none" return attrs_config