core: use functions instead of evals for storing attributes to qubes.xml
This commit is contained in:
parent
e9fe890acb
commit
04f86c7059
@ -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:
|
||||
|
@ -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'] = {
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user