Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit be80b24

Browse files
elmarcocrobinso
authored andcommitted
Allow specifying channel address type
This turned out to be unnecessary for default Spicevmc channel, but can still be useful.
1 parent a7a00f0 commit be80b24

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

virtinst/VirtualCharDevice.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class VirtualCharDevice(VirtualDevice.VirtualDevice):
6363
target_types = [ CHAR_CHANNEL_TARGET_GUESTFWD,
6464
CHAR_CHANNEL_TARGET_VIRTIO ]
6565

66+
CHAR_CHANNEL_ADDRESS_VIRTIO_SERIAL = "virtio-serial"
67+
address_types = [ CHAR_CHANNEL_ADDRESS_VIRTIO_SERIAL ]
68+
6669
CHAR_CONSOLE_TARGET_SERIAL = "serial"
6770
CHAR_CONSOLE_TARGET_UML = "uml"
6871
CHAR_CONSOLE_TARGET_XEN = "xen"
@@ -182,6 +185,7 @@ def __init__(self, conn, dev_type,
182185
self._bind_host = None
183186
self._bind_port = None
184187
self._protocol = self.CHAR_PROTOCOL_RAW
188+
self._address_type = None
185189

186190
if self.char_type == self.CHAR_UDP:
187191
self._source_mode = self.CHAR_MODE_CONNECT
@@ -329,6 +333,17 @@ def get_target_name(self):
329333
doc=_("Sysfs Name of virtio port in the guest"),
330334
xpath="./target/@name")
331335

336+
def get_address_type(self):
337+
return self._address_type
338+
def set_address_type(self, val):
339+
if val not in self.address_types:
340+
raise ValueError(_("Unknown address type '%s'. Must be in: ") % val,
341+
self.address_types)
342+
self._address_type = val
343+
address_type = _xml_property(get_address_type, set_address_type,
344+
doc=_("Channel type as exposed in the guest."),
345+
xpath="./address/@type")
346+
332347
# XML building helpers
333348
def _char_empty_xml(self):
334349
"""
@@ -381,6 +396,15 @@ def _get_target_xml(self):
381396
xml += "/>\n"
382397
return xml
383398

399+
def _get_address_xml(self):
400+
xml = ""
401+
if not self.address_type:
402+
return xml
403+
404+
xml = " <address type='%s'" % self.address_type
405+
xml += "/>\n"
406+
return xml
407+
384408

385409
def _get_xml_config(self):
386410
xml = " <%s type='%s'" % (self._dev_type, self._char_type)
@@ -394,14 +418,24 @@ def _get_xml_config(self):
394418
"Target parameters not used with '%s' devices, only '%s'" %
395419
(self._dev_type, self.DEV_CHANNEL))
396420

397-
if char_xml or target_xml:
421+
address_xml = self._get_address_xml()
422+
has_address = self._target_type == self.CHAR_CHANNEL_TARGET_VIRTIO
423+
if address_xml and not has_address:
424+
raise RuntimeError(
425+
"Address parameters not used with '%s' target, only '%s'" %
426+
(self._target_type, self.CHAR_CHANNEL_TARGET_VIRTIO))
427+
428+
if char_xml or target_xml or address_xml:
398429
xml += ">"
399430
if char_xml:
400431
xml += "\n%s" % char_xml
401432

402433
if target_xml:
403434
xml += "\n%s" % target_xml
404435

436+
if address_xml:
437+
xml += "\n%s" % target_xml
438+
405439
xml += " </%s>" % self._dev_type
406440
else:
407441
xml += "/>"

0 commit comments

Comments
 (0)