devices: redirdev: Use CharSource

redirdev does the same internally for libvirt, so let's follow that
pattern, and fix the fallout
This commit is contained in:
Cole Robinson 2019-05-13 14:59:33 -04:00
parent 6d46e37e09
commit 9d78759ac5
6 changed files with 20 additions and 16 deletions

View File

@ -494,6 +494,14 @@ Foo bar baz & yeah boii < > yeahfoo
<address type='usb' bus='0' port='4'/>
<boot order='7'/>
</redirdev>
<redirdev bus='usb' type='unix'>
<source mode='connect' path='/tmp/connect.socket'/>
<protocol type='raw'/>
</redirdev>
<redirdev bus='usb' type='unix'>
<source mode='bind' path='/tmp/listen.socket'/>
<protocol type='raw'/>
</redirdev>
<redirfilter>
<usbdev class='0x08' vendor='0x15E1' product='0x2007' version='1.10' allow='yes'/>
<usbdev class='-1' vendor='-1' product='-1' version='-1' allow='no'/>

View File

@ -984,8 +984,8 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(dev1)
check("bus", "usb", "baz", "usb")
check("host", "foo", "bar")
check("service", 12, 42)
check("source.host", "foo", "bar")
check("source.service", 12, 42)
check = self._make_checker(dev2)
check("type", "tcp", "spicevmc")

View File

@ -2300,7 +2300,7 @@ class vmmDetails(vmmGObjectUI):
def refresh_redir_page(self, rd):
address = None
if rd.type == 'tcp':
address = _("%s:%s") % (rd.host, rd.service)
address = _("%s:%s") % (rd.source.host, rd.source.service)
self.widget("redir-title").set_markup(_label_for_device(rd))
self.widget("redir-type").set_text(rd.pretty_type(rd.type))

View File

@ -3080,7 +3080,7 @@ class ParserRedir(VirtCLIParser):
stub_none = False
def set_server_cb(self, inst, val, virtarg):
inst.parse_friendly_server(val)
inst.source.set_friendly_host(val)
def _parse(self, inst):
if self.optstr == "none":

View File

@ -33,7 +33,11 @@ class CharSource(XMLBuilder):
_set_host_helper(self, "connect_host", "connect_service", val)
def set_friendly_bind(self, val):
_set_host_helper(self, "bind_host", "bind_service", val)
def set_friendly_host(self, val):
_set_host_helper(self, "host", "service", val)
host = XMLProperty("./@host")
service = XMLProperty("./@service", is_int=True)
path = XMLProperty("./@path")
channel = XMLProperty("./@channel")
master = XMLProperty("./@master")

View File

@ -4,8 +4,9 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
from .char import CharSource
from .device import Device
from ..xmlbuilder import XMLProperty
from ..xmlbuilder import XMLChildProperty, XMLProperty
class DeviceRedirdev(Device):
@ -19,20 +20,11 @@ class DeviceRedirdev(Device):
return "SpiceVMC"
return typ and typ.capitalize()
def parse_friendly_server(self, serverstr):
if serverstr.count(":") != 1:
raise ValueError(_("Could not determine or unsupported "
"format of '%s'") % serverstr)
self.host, self.service = serverstr.split(":")
_XML_PROP_ORDER = ["bus", "type"]
_XML_PROP_ORDER = ["bus", "type", "source"]
bus = XMLProperty("./@bus")
type = XMLProperty("./@type")
host = XMLProperty("./source/@host")
service = XMLProperty("./source/@service", is_int=True)
source = XMLChildProperty(CharSource, is_single=True)
##################