nodedev: add is_linux_root_hub helper

Move the check out of connection.py, and simplify the addhardware
code
This commit is contained in:
Cole Robinson 2018-10-13 12:18:50 -04:00
parent 467c524684
commit c23a0d4c96
3 changed files with 16 additions and 25 deletions

View File

@ -531,22 +531,23 @@ class vmmAddHardware(vmmGObjectUI):
host_dev_model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
host_dev.append_column(host_col)
def _populate_hostdev_model(self, devtype, devcap, subtype, subcap):
def _populate_hostdev_model(self, devtype):
devlist = self.widget("host-device")
model = devlist.get_model()
model.clear()
subdevs = []
if subtype:
subdevs = self.conn.filter_nodedevs(subtype, subcap)
devs = self.conn.filter_nodedevs(devtype, devcap)
devs = self.conn.filter_nodedevs(devtype)
netdevs = self.conn.filter_nodedevs("net")
for dev in devs:
if devtype == "usb_device" and dev.xmlobj.is_linux_root_hub():
continue
prettyname = dev.xmlobj.pretty_name()
for subdev in subdevs:
if dev.xmlobj.name == subdev.xmlobj.parent:
prettyname += " (%s)" % subdev.xmlobj.pretty_name()
if devtype == "pci":
for subdev in netdevs:
if dev.xmlobj.name == subdev.xmlobj.parent:
prettyname += " (%s)" % subdev.xmlobj.pretty_name()
model.append([dev.xmlobj, prettyname])
@ -755,16 +756,11 @@ class vmmAddHardware(vmmGObjectUI):
if page == PAGE_HOSTDEV:
# Need to do this here, since we share the hostdev page
# between two different HW options
pci_info = ["pci", None, "net", "80203"]
usb_info = ["usb_device", None, None, None]
row = self._get_hw_selection()
devtype = "usb_device"
if row and row[5] == "pci":
info = pci_info
else:
info = usb_info
(devtype, devcap, subtype, subcap) = info
self._populate_hostdev_model(devtype, devcap, subtype, subcap)
devtype = "pci"
self._populate_hostdev_model(devtype)
if page == PAGE_CONTROLLER:
# We need to trigger this as it can desensitive 'finish'

View File

@ -637,15 +637,6 @@ class vmmConnection(vmmGObject):
xmlobj.capability_type != devcap):
continue
if (devtype == "usb_device" and
(("Linux Foundation" in str(xmlobj.vendor_name) or
("Linux" in str(xmlobj.vendor_name) and
xmlobj.vendor_id == "0x1d6b")) and
("root hub" in str(xmlobj.product_name) or
("host controller" in str(xmlobj.product_name).lower() and
str(xmlobj.product_id).startswith("0x000"))))):
continue
retdevs.append(dev)
return retdevs

View File

@ -200,6 +200,10 @@ class USBDevice(NodeDevice):
vendor_name = XMLProperty("./capability/vendor")
vendor_id = XMLProperty("./capability/vendor/@id")
def is_linux_root_hub(self):
return (self.vendor_id == "0x1d6b" and
self.product_id in ["0x0001", "0x0002", "0x0003"])
def pretty_name(self):
# Hypervisor may return a rather sparse structure, missing
# some ol all stringular descriptions of the device altogether.