From 2a42b7c7c7ebd6db9225cf66344552a3f58da5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 29 May 2019 23:47:09 +0200 Subject: [PATCH] vm/net: make 'dns' property visible in Admin API Serialize the list with a space as a separator. QubesOS/qubes-issues#5050 --- qubes/vm/mix/net.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py index baa8732b..51fd1af0 100644 --- a/qubes/vm/mix/net.py +++ b/qubes/vm/mix/net.py @@ -91,6 +91,16 @@ def _setter_provides_network(self, prop, value): return value +class StrSerializableTuple(tuple): + def __str__(self): + # verify it can be deserialized later(currently 'dns' + # property is the only using this, and it is safe) + if any(' ' in el for el in self): + raise ValueError( + 'space found in a list element {!r}'.format(self)) + return ' '.join(self) + + class NetVMMixin(qubes.events.Emitter): ''' Mixin containing network functionality ''' mac = qubes.property('mac', type=str, @@ -224,14 +234,14 @@ class NetVMMixin(qubes.events.Emitter): # used in both # - @property + @qubes.stateless_property def dns(self): - '''Secondary DNS server set up for this domain.''' + '''DNS servers set up for this domain.''' if self.netvm is not None or self.provides_network: - return ( + return StrSerializableTuple(( '10.139.1.1', '10.139.1.2', - ) + )) return None