Subject: guest: Query availability of usb redirdevs in domcaps From: Lin Ma lma@suse.com Thu Nov 10 15:57:08 2022 +0800 Date: Wed Dec 14 12:44:54 2022 -0500: Git: 8cc6ee8da36d518ec928c072822bbee6ebe2e362 Signed-off-by: Lin Ma diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py index 1b5b6bf6..91f51f9f 100644 --- a/virtinst/domcapabilities.py +++ b/virtinst/domcapabilities.py @@ -113,6 +113,7 @@ class _Devices(_CapsBlock): graphics = XMLChildProperty(_make_capsblock("graphics"), is_single=True) tpm = XMLChildProperty(_make_capsblock("tpm"), is_single=True) filesystem = XMLChildProperty(_make_capsblock("filesystem"), is_single=True) + redirdev = XMLChildProperty(_make_capsblock("redirdev"), is_single=True) class _Features(_CapsBlock): @@ -448,6 +449,18 @@ class DomainCapabilities(XMLBuilder): return self.devices.graphics.get_enum("type").has_value("spice") + def supports_redirdev_usb(self): + """ + Return False if libvirt explicitly advertises no support for + USB redirect + """ + if self.devices.redirdev.supported is None: + # Follow the original behavior in case of talking to older + # libvirt. + return True + + return self.devices.redirdev.get_enum("bus").has_value("usb") + def supports_filesystem_virtiofs(self): """ Return True if libvirt advertises support for virtiofs diff --git a/virtinst/guest.py b/virtinst/guest.py index e6636022..1d1e2ee9 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -1155,6 +1155,8 @@ class Guest(XMLBuilder): self.add_device(dev) def _add_spice_usbredir(self): + if not self.lookup_domcaps().supports_redirdev_usb(): + return if self.skip_default_usbredir: return if self.devices.redirdev: