VirtualRedir: Convert to new style XML props

This commit is contained in:
Cole Robinson 2013-07-15 12:57:37 -04:00
parent b6f2d99db2
commit 98a4d86d7f
8 changed files with 52 additions and 95 deletions

View File

@ -640,10 +640,6 @@ vinst.add_valid("redirdev", "--redirdev usb,type=tcp,server=127.0.0.1:4002") #
vinst.add_invalid("redirdev", "--redirdev") # Missing argument
vinst.add_invalid("redirdev", "--redirdev pci") # Unsupported bus
vinst.add_invalid("redirdev", "--redirdev usb,type=spicevmc,server=foo:12") # Invalid argument
vinst.add_invalid("redirdev", "--redirdev usb,type=tcp,server=") # Missing argument
vinst.add_invalid("redirdev", "--redirdev usb,type=tcp,server=localhost:p4000") # Invalid address
vinst.add_invalid("redirdev", "--redirdev usb,type=tcp,server=localhost:") # Missing address
vinst.add_invalid("redirdev", "--redirdev usb,type=tcp,server=:399") # Missing host
vinst.add_category("hostdev", "--noautoconsole --nographics --nodisks --pxe")

View File

@ -94,6 +94,10 @@
</source>
</hostdev>
<watchdog model="ib700" action="none"/>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="tcp">
<source host="foobar.com" service="1234"/>
</redirdev>
<memballoon model="virtio"/>
</devices>
<seclabel type="static" model="selinux">

View File

@ -852,6 +852,15 @@ class TestXMLConfig(unittest.TestCase):
g.seclabel.label = "foolabel"
g.seclabel.imagelabel = "imagelabel"
redir1 = virtinst.VirtualRedirDevice(g.conn)
redir1.type = "spicevmc"
redir2 = virtinst.VirtualRedirDevice(g.conn)
redir2.type = "tcp"
redir2.parse_friendly_server("foobar.com:1234")
g.add_device(redir1)
g.add_device(redir2)
self._compare(g, "boot-many-devices", False)
def testCpuset(self):

View File

@ -32,6 +32,6 @@
<redirdev bus="usb" type="tcp">
<source mode="connect" host="foo" service="12"/>
</redirdev>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="tcp"/>
</devices>
</domain>

View File

@ -691,11 +691,12 @@ class XMLParseTest(unittest.TestCase):
dev2 = guest.get_devices("redirdev")[1]
check = self._make_checker(dev1)
check("bus", "usb", "baz", "usb")
check("host", "foo", "bar")
check("service", "12", "42")
check("service", 12, 42)
check = self._make_checker(dev2)
check("type", "spicevmc")
check("type", "tcp", "spicevmc")
self._alter_compare(guest.get_xml_config(), outfile)

View File

@ -1601,7 +1601,8 @@ class vmmAddHardware(vmmGObjectUI):
service = self.get_config_usbredir_service()
try:
self._dev = VirtualRedirDevice(conn, bus="usb", stype=stype)
self._dev = VirtualRedirDevice(conn)
self._dev.type = stype
if host:
self._dev.host = host
if service:

View File

@ -28,83 +28,27 @@ class VirtualRedirDevice(VirtualDevice):
_virtual_device_type = VirtualDevice.VIRTUAL_DEV_REDIRDEV
BUS_DEFAULT = "usb"
_buses = ["usb"]
BUS_DEFAULT = "default"
BUSES = ["usb"]
TYPE_DEFAULT = "spicevmc"
_types = ["tcp", "spicevmc", None]
def __init__(self, conn, bus=BUS_DEFAULT, stype=TYPE_DEFAULT,
parsexml=None, parsexmlnode=None):
VirtualDevice.__init__(self, conn, parsexml, parsexmlnode)
self._type = None
self._bus = None
self._host = None
self._service = None
if self._is_parse():
return
self.bus = bus
self.type = stype
def get_buses(self):
return self._buses[:]
buses = property(get_buses)
def get_bus(self):
return self._bus
def set_bus(self, new_val):
if new_val not in self.buses:
raise ValueError(_("Unsupported bus '%s'" % new_val))
self._bus = new_val
bus = XMLProperty(get_bus, set_bus,
xpath="./@bus")
def get_types(self):
return self._types[:]
types = property(get_types)
def get_type(self):
return self._type
def set_type(self, new_val):
if new_val not in self.types:
raise ValueError(_("Unsupported redirection type '%s'" % new_val))
self._type = new_val
type = XMLProperty(get_type, set_type,
xpath="./@type")
def get_host(self):
return self._host
def set_host(self, val):
if len(val) == 0:
raise ValueError(_("Invalid host value"))
self._host = val
host = XMLProperty(get_host, set_host,
xpath="./source/@host")
def get_service(self):
return self._service
def set_service(self, val):
int(val)
self._service = val
service = XMLProperty(get_service, set_service,
xpath="./source/@service")
TYPE_DEFAULT = "default"
TYPES = ["tcp", "spicevmc", TYPE_DEFAULT]
def parse_friendly_server(self, serverstr):
if serverstr.count(":") == 1:
self.host, self.service = serverstr.split(":")
else:
raise ValueError(_("Could not determine or unsupported format of '%s'") % serverstr)
if serverstr.count(":") != 1:
raise ValueError(_("Could not determine or unsupported "
"format of '%s'") % serverstr)
self.host, self.service = serverstr.split(":")
def _get_xml_config(self):
xml = (" <redirdev bus='%s' type='%s'" %
(self.bus, self.type))
if self.type == 'spicevmc':
xml += "/>"
return xml
xml += ">\n"
xml += (" <source mode='connect' host='%s' service='%s'/>\n" %
(self.host, self.service))
xml += " </redirdev>"
return xml
_XML_PROP_ORDER = ["bus", "type"]
bus = XMLProperty(xpath="./@bus",
default_cb=lambda s: "usb",
default_name=BUS_DEFAULT)
type = XMLProperty(xpath="./@type",
default_cb=lambda s: "spicevmc",
default_name=TYPE_DEFAULT)
host = XMLProperty(xpath="./source/@host")
service = XMLProperty(xpath="./source/@service", is_int=True)

View File

@ -1701,27 +1701,29 @@ def parse_redirdev(guest, optstring, dev=None):
# Peel the mode off the front
opts = parse_optstr(optstring, remove_first="bus")
bus = get_opt_param(opts, "bus")
stype = get_opt_param(opts, "type")
server = get_opt_param(opts, "server")
if bus == "none":
if opts.get("bus") == "none":
return None
if not dev:
dev = virtinst.VirtualRedirDevice(bus=bus,
stype=stype,
conn=guest.conn)
dev = virtinst.VirtualRedirDevice(guest.conn)
if stype == "spicevmc" and server:
raise ValueError(_("The server option is invalid with spicevmc redirection"))
if stype == "tcp" and not server:
raise ValueError(_("The server option is missing for TCP redirection"))
set_param = _build_set_param(dev, opts)
set_param("bus", "bus")
set_param("type", "type")
if server:
dev.parse_friendly_server(server)
if dev.type == "spicevmc" and server:
raise ValueError(
_("The server option is invalid with spicevmc redirection"))
if dev.type == "tcp" and not server:
raise ValueError(
_("The server option is missing for TCP redirection"))
if opts:
raise ValueError(_("Unknown options %s") % opts.keys())