Add stateless_property decorator for properties exposed through mgmt API

Management API gives access only to qubes.property. And this is
actually a good thing, so instead of extending it to access also
builtins.property, add a simple decorator to define read-only, stateless
qubes.property.

QubesOS/qubes-issues#2622
This commit is contained in:
Marek Marczykowski-Górecki 2017-04-10 04:02:13 +02:00
parent 2aa0de3d5b
commit 99be78646f
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 15 additions and 5 deletions

View File

@ -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`

View File

@ -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

View File

@ -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.