devices: char: Rename some properties to better match XML

* bind_port -> bind_service
* source_host -> connect_host
* source_port -> connect_service
This commit is contained in:
Cole Robinson 2019-05-13 11:31:18 -04:00
parent a6495bb38f
commit e6eb1d447b
4 changed files with 48 additions and 55 deletions

View File

@ -518,9 +518,9 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(serial1)
check("type", "null", "udp")
check("bind_host", None, "example.com")
check("bind_port", None, 66)
check("source_host", None, "example.com.uk")
check("source_port", None, 77)
check("bind_service", None, 66)
check("connect_host", None, "example.com.uk")
check("connect_service", None, 77)
check = self._make_checker(serial2)
check("type", "tcp")
@ -534,10 +534,10 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(parallel2)
check("type", "udp")
check("bind_port", 1111, 1357)
check("bind_service", 1111, 1357)
check("bind_host", "my.bind.host", "my.foo.host")
check("source_port", 2222, 7777)
check("source_host", "my.source.host", "source.foo.host")
check("connect_service", 2222, 7777)
check("connect_host", "my.source.host", "source.foo.host")
check = self._make_checker(console1)
check("type", "pty")

View File

@ -2352,8 +2352,7 @@ class vmmDetails(vmmGObjectUI):
["serial", "parallel"])
show_target_name = chardev.DEVICE_TYPE == "channel"
def show_ui(param, val=None):
widgetname = "char-" + param.replace("_", "-")
def show_ui(widgetname, param, val=None):
doshow = chardev.supports_property(param, ro=True)
# Exception: don't show target type for serial/parallel
@ -2369,12 +2368,12 @@ class vmmDetails(vmmGObjectUI):
self.widget(widgetname).set_text(val or "-")
def build_host_str(base):
if (not chardev.supports_property(base + "_host") or
not chardev.supports_property(base + "_port")):
if (not chardev.supports_property(base + "_service") or
not chardev.supports_property(base + "_service")):
return ""
host = getattr(chardev, base + "_host") or ""
port = getattr(chardev, base + "_port") or ""
port = getattr(chardev, base + "_service") or ""
ret = str(host)
if port:
@ -2411,12 +2410,12 @@ class vmmDetails(vmmGObjectUI):
self.widget("char-dev-type").set_text(dev_type)
# Device type specific properties, only show if apply to the cur dev
show_ui("source_host", build_host_str("source"))
show_ui("bind_host", build_host_str("bind"))
show_ui("source_path")
show_ui("target_type")
show_ui("target_name")
show_ui("target_state")
show_ui("char-source-host", "connect_host", build_host_str("connect"))
show_ui("char-bind-host", "bind_host", build_host_str("bind"))
show_ui("char-source-path", "source_path")
show_ui("char-target-type", "target_type")
show_ui("char-target-name", "target_name")
show_ui("char-target-state", "target_state")
def refresh_hostdev_page(self, hostdev):
rom_bar = hostdev.rom_bar

View File

@ -3336,7 +3336,7 @@ class _ParserChar(VirtCLIParser):
self.optdict.get("mode", None) == "bind"):
inst.set_friendly_bind(val)
else:
inst.set_friendly_source(val)
inst.set_friendly_connect(val)
def set_bind_cb(self, inst, val, virtarg):
inst.set_friendly_bind(val)

View File

@ -99,16 +99,17 @@ class _DeviceChar(Device):
"""
users = {
"source_path": [self.TYPE_FILE, self.TYPE_UNIX,
self.TYPE_DEV, self.TYPE_PIPE],
self.TYPE_DEV, self.TYPE_PIPE],
"source_mode": [self.TYPE_UNIX, self.TYPE_TCP],
"source_host": [self.TYPE_TCP, self.TYPE_UDP],
"source_port": [self.TYPE_TCP, self.TYPE_UDP],
"source_channel": [self.TYPE_SPICEPORT],
"source_master": [self.TYPE_NMDM],
"source_slave": [self.TYPE_NMDM],
"protocol": [self.TYPE_TCP],
"bind_host": [self.TYPE_UDP],
"bind_port": [self.TYPE_UDP],
"bind_service": [self.TYPE_UDP],
"connect_host": [self.TYPE_TCP, self.TYPE_UDP],
"connect_service": [self.TYPE_TCP, self.TYPE_UDP],
}
if ro:
@ -131,24 +132,40 @@ class _DeviceChar(Device):
if port:
setattr(self, portparam, port)
def set_friendly_source(self, val):
self._set_host_helper("source_host", "source_port", val)
def set_friendly_connect(self, val):
self._set_host_helper("connect_host", "connect_service", val)
def set_friendly_bind(self, val):
self._set_host_helper("bind_host", "bind_port", val)
self._set_host_helper("bind_host", "bind_service", val)
def set_friendly_target(self, val):
self._set_host_helper("target_address", "target_port", val)
_XML_PROP_ORDER = ["type",
"bind_host", "bind_port",
"source_mode", "source_host", "source_port",
"bind_host", "bind_service",
"source_mode", "connect_host", "connect_service",
"_source_path", "source_channel",
"target_type", "target_name", "target_state"]
type = XMLProperty("./@type")
_tty = XMLProperty("./@tty")
_source_path = XMLProperty("./source/@path")
_source_path = XMLProperty("./source/@path")
source_channel = XMLProperty("./source/@channel")
source_master = XMLProperty("./source/@master")
source_slave = XMLProperty("./source/@slave")
source_mode = XMLProperty("./source/@mode")
target_address = XMLProperty("./target/@address")
target_port = XMLProperty("./target/@port", is_int=True)
target_type = XMLProperty("./target/@type")
target_name = XMLProperty("./target/@name")
target_state = XMLProperty("./target/@state")
protocol = XMLProperty("./protocol/@type")
log_file = XMLProperty("./log/@file")
log_append = XMLProperty("./log/@append", is_onoff=True)
# Convenience property to get source_path or tty, for old libvirt compat
def _get_source_path(self):
source = self._source_path
if source is None and self._tty:
@ -158,41 +175,18 @@ class _DeviceChar(Device):
self._source_path = val
source_path = property(_get_source_path, _set_source_path)
source_channel = XMLProperty("./source/@channel")
source_master = XMLProperty("./source/@master")
source_slave = XMLProperty("./source/@slave")
target_state = XMLProperty("./target/@state")
###################
# source handling #
###################
source_mode = XMLProperty("./source/@mode")
source_host = XMLProperty("./source[@mode='connect']/@host")
source_port = XMLProperty(
# Convenience source helpers for setting connect/bind host and service
connect_host = XMLProperty("./source[@mode='connect']/@host")
connect_service = XMLProperty(
"./source[@mode='connect']/@service", is_int=True)
bind_host = XMLProperty("./source[@mode='bind']/@host")
bind_port = XMLProperty("./source[@mode='bind']/@service", is_int=True)
bind_service = XMLProperty("./source[@mode='bind']/@service", is_int=True)
#######################
# Remaining XML props #
#######################
protocol = XMLProperty("./protocol/@type")
target_address = XMLProperty("./target/@address")
target_port = XMLProperty("./target/@port", is_int=True)
target_type = XMLProperty("./target/@type")
target_name = XMLProperty("./target/@name")
log_file = XMLProperty("./log/@file")
log_append = XMLProperty("./log/@append", is_onoff=True)
##################
# Default config #