QubesVm: add attribute setter hook mechanism

This is part of #827 bug.
This commit is contained in:
Wojciech Zygmunt Porczyk 2014-05-05 16:31:06 +02:00
parent b8b2733114
commit 72f74b6b76

View File

@ -74,6 +74,7 @@ class QubesVm(object):
hooks_remove_from_disk = []
hooks_start = []
hooks_verify_files = []
hooks_set_attr = []
def get_attrs_config(self):
""" Object attributes for serialization/deserialization
@ -129,7 +130,7 @@ class QubesVm(object):
eval(value) if value.find("[") >= 0 else
eval("[" + value + "]") },
# Internal VM (not shown in qubes-manager, doesn't create appmenus entries
"internal": { "default": False },
"internal": { "default": False, 'attr': '_internal' },
"vcpus": { "default": None },
"uses_default_kernel": { "default": True, 'order': 30 },
"uses_default_kernelopts": { "default": True, 'order': 30 },
@ -218,6 +219,10 @@ class QubesVm(object):
attrs = hook(self, attrs)
return attrs
def post_set_attr(self, attr, value):
for hook in self.hooks_set_attr:
hook(self, attr, value)
def __basic_parse_xml_attr(self, value):
if value is None:
return None
@ -512,6 +517,15 @@ class QubesVm(object):
for hook in self.hooks_post_rename:
hook(self, old_name)
@property
def internal(self):
return self._internal
@internal.setter
def internal(self, value):
self._internal = value
self.post_set_attr('internal', value)
@property
def autostart(self):
return self._autostart