diff --git a/qubes/__init__.py b/qubes/__init__.py index 44b7156b..48c8bd97 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -407,6 +407,16 @@ class property(object): # pylint: disable=redefined-builtin,invalid-name return bool(value) +def stateless_property(func): + '''Decorator similar to :py:class:`builtins.property`, but for properties + exposed through management API (including qvm-prefs etc)''' + return property(func.__name__, + setter=property.forbidden, + saver=property.DontSave, + default=func, + doc=func.__doc__) + + class PropertyHolder(qubes.events.Emitter): '''Abstract class for holding :py:class:`qubes.property` diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index 1ce9d651..36c28255 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -98,19 +98,19 @@ class NetVMMixin(qubes.events.Emitter): # - @property + @qubes.stateless_property def visible_ip(self): '''IP address of this domain as seen by the domain.''' return self.features.check_with_template('net/fake-ip', None) or \ self.ip - @property + @qubes.stateless_property def visible_gateway(self): '''Default gateway of this domain as seen by the domain.''' return self.features.check_with_template('net/fake-gateway', None) or \ self.netvm.gateway - @property + @qubes.stateless_property def visible_netmask(self): '''Netmask as seen by the domain.''' return self.features.check_with_template('net/fake-netmask', None) or \ @@ -133,7 +133,7 @@ class NetVMMixin(qubes.events.Emitter): # does not happen, because qid < 253, but may happen in the future. return '10.137.{}.{}'.format((vm.qid >> 8) & 7, vm.qid & 7) - @property + @qubes.stateless_property def gateway(self): '''Gateway for other domains that use this domain as netvm.''' return self.visible_ip if self.provides_network else None diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 30ae8e8a..15b88396 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -502,7 +502,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # VMM-related - @property + @qubes.stateless_property def xid(self): '''Xen ID.