mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-03-09 08:58:27 +03:00
nodedev: Fold PCIDevice into NodeDevice
This commit is contained in:
parent
ca804c5b5e
commit
a0881bc6f2
@ -78,25 +78,24 @@ class TestNodeDev(unittest.TestCase):
|
||||
self.assertEqual(dev.interface, "eth0")
|
||||
self.assertEqual(dev.pretty_name(), "Interface eth0")
|
||||
|
||||
def testPCIDevice1(self):
|
||||
def testPCIDevice(self):
|
||||
devname = "pci_1180_592"
|
||||
vals = {"name": "pci_1180_592", "parent": "pci_8086_2448",
|
||||
"device_type": NodeDevice.CAPABILITY_TYPE_PCI,
|
||||
"domain": "0", "bus": "21", "slot": "0", "function": "4",
|
||||
"product_id": "0x0592", "vendor_id": "0x1180",
|
||||
"product_name": "R5C592 Memory Stick Bus Host Adapter",
|
||||
"vendor_name": "Ricoh Co Ltd"}
|
||||
self._testCompare(devname, vals)
|
||||
dev = self._nodeDevFromName(devname)
|
||||
self.assertEqual(dev.pretty_name(),
|
||||
"0000:15:00:4 Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter")
|
||||
|
||||
def testPCIDevice2(self):
|
||||
devname = "pci_8086_1049"
|
||||
vals = {"name": "pci_8086_1049", "parent": "computer",
|
||||
"device_type": NodeDevice.CAPABILITY_TYPE_PCI,
|
||||
"domain": "0", "bus": "0", "slot": "25", "function": "0",
|
||||
"product_id": "0x1049", "vendor_id": "0x8086",
|
||||
"product_name": "82566MM Gigabit Network Connection",
|
||||
"vendor_name": "Intel Corporation"}
|
||||
self._testCompare(devname, vals)
|
||||
dev = self._nodeDevFromName(devname)
|
||||
self.assertEqual(dev.pretty_name(),
|
||||
"0000:00:19:0 Intel Corporation 82566MM Gigabit Network Connection")
|
||||
|
||||
nodename = "pci_8086_10fb"
|
||||
obj = self._nodeDevFromName(nodename)
|
||||
self.assertEqual(obj.is_pci_sriov(), True)
|
||||
nodename = "pci_8086_2448"
|
||||
obj = self._nodeDevFromName(nodename)
|
||||
self.assertEqual(obj.is_pci_bridge(), True)
|
||||
|
||||
|
||||
def testUSBDevDevice1(self):
|
||||
devname = "usb_device_781_5151_2004453082054CA1BEEE"
|
||||
@ -213,16 +212,6 @@ class TestNodeDev(unittest.TestCase):
|
||||
devfile = "pcidev.xml"
|
||||
self._testNode2DeviceCompare(nodename, devfile)
|
||||
|
||||
def testPCIParse(self):
|
||||
nodename = "pci_1180_476"
|
||||
obj = self._nodeDevFromName(nodename)
|
||||
self.assertEqual(obj.iommu_group, 3)
|
||||
|
||||
def testNodeDevSRIOV(self):
|
||||
nodename = "pci_8086_10fb"
|
||||
obj = self._nodeDevFromName(nodename)
|
||||
self.assertEqual(obj.capability_type, "virt_functions")
|
||||
|
||||
def testNodeDevFail(self):
|
||||
nodename = "usb_device_1d6b_1_0000_00_1d_1_if0"
|
||||
devfile = ""
|
||||
|
@ -538,8 +538,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
for dev in devs:
|
||||
if devtype == "usb_device" and dev.xmlobj.is_linux_root_hub():
|
||||
continue
|
||||
if (devtype == "pci" and
|
||||
dev.xmlobj.capability_type == "pci-bridge"):
|
||||
if dev.xmlobj.is_pci_bridge():
|
||||
continue
|
||||
prettyname = dev.xmlobj.pretty_name()
|
||||
|
||||
|
@ -159,7 +159,7 @@ class vmmCreateNetwork(vmmGObjectUI):
|
||||
devprettynames = []
|
||||
ifnames = []
|
||||
for pcidev in self.conn.filter_nodedevs("pci"):
|
||||
if pcidev.xmlobj.capability_type != "virt_functions":
|
||||
if not pcidev.xmlobj.is_pci_sriov():
|
||||
continue
|
||||
devdesc = pcidev.xmlobj.pretty_name()
|
||||
for netdev in self.conn.filter_nodedevs("net"):
|
||||
|
@ -110,7 +110,15 @@ class NodeDevice(XMLBuilder):
|
||||
return None
|
||||
|
||||
def compare_to_hostdev(self, hostdev):
|
||||
ignore = hostdev
|
||||
if self.device_type == "pci":
|
||||
if hostdev.type != self.device_type:
|
||||
return False
|
||||
|
||||
return (_compare_int(self.domain, hostdev.domain) and
|
||||
_compare_int(self.bus, hostdev.bus) and
|
||||
_compare_int(self.slot, hostdev.slot) and
|
||||
_compare_int(self.function, hostdev.function))
|
||||
|
||||
return False
|
||||
|
||||
def pretty_name(self):
|
||||
@ -124,9 +132,25 @@ class NodeDevice(XMLBuilder):
|
||||
if self.device_type == "net":
|
||||
if self.interface:
|
||||
ret = _("Interface %s") % self.interface
|
||||
if self.device_type == "pci":
|
||||
devstr = "%.4X:%.2X:%.2X:%X" % (int(self.domain),
|
||||
int(self.bus),
|
||||
int(self.slot),
|
||||
int(self.function))
|
||||
ret = "%s %s %s" % (devstr, self._vendor_name, self._product_name)
|
||||
return ret
|
||||
|
||||
|
||||
########################
|
||||
# XML helper functions #
|
||||
########################
|
||||
|
||||
def is_pci_sriov(self):
|
||||
return self._capability_type == "virt_functions"
|
||||
def is_pci_bridge(self):
|
||||
return self._capability_type == "pci-bridge"
|
||||
|
||||
|
||||
##################
|
||||
# XML properties #
|
||||
##################
|
||||
@ -134,38 +158,15 @@ class NodeDevice(XMLBuilder):
|
||||
# type='net' options
|
||||
interface = XMLProperty("./capability/interface")
|
||||
|
||||
|
||||
class PCIDevice(NodeDevice):
|
||||
# type='pci' options
|
||||
domain = XMLProperty("./capability/domain")
|
||||
bus = XMLProperty("./capability/bus")
|
||||
slot = XMLProperty("./capability/slot")
|
||||
function = XMLProperty("./capability/function")
|
||||
_product_name = XMLProperty("./capability/product")
|
||||
_vendor_name = XMLProperty("./capability/vendor")
|
||||
_capability_type = XMLProperty("./capability/capability/@type")
|
||||
|
||||
product_name = XMLProperty("./capability/product")
|
||||
product_id = XMLProperty("./capability/product/@id")
|
||||
vendor_name = XMLProperty("./capability/vendor")
|
||||
vendor_id = XMLProperty("./capability/vendor/@id")
|
||||
|
||||
capability_type = XMLProperty("./capability/capability/@type")
|
||||
|
||||
iommu_group = XMLProperty("./capability/iommuGroup/@number", is_int=True)
|
||||
|
||||
def pretty_name(self):
|
||||
devstr = "%.4X:%.2X:%.2X:%X" % (int(self.domain),
|
||||
int(self.bus),
|
||||
int(self.slot),
|
||||
int(self.function))
|
||||
|
||||
return "%s %s %s" % (devstr, self.vendor_name, self.product_name)
|
||||
|
||||
def compare_to_hostdev(self, hostdev):
|
||||
if hostdev.type != self.device_type:
|
||||
return False
|
||||
|
||||
return (_compare_int(self.domain, hostdev.domain) and
|
||||
_compare_int(self.bus, hostdev.bus) and
|
||||
_compare_int(self.slot, hostdev.slot) and
|
||||
_compare_int(self.function, hostdev.function))
|
||||
|
||||
|
||||
class USBDevice(NodeDevice):
|
||||
@ -373,9 +374,7 @@ def _AddressStringToNodedev(conn, addrstr):
|
||||
|
||||
|
||||
def _typeToDeviceClass(t):
|
||||
if t == NodeDevice.CAPABILITY_TYPE_PCI:
|
||||
return PCIDevice
|
||||
elif t == NodeDevice.CAPABILITY_TYPE_USBDEV:
|
||||
if t == NodeDevice.CAPABILITY_TYPE_USBDEV:
|
||||
return USBDevice
|
||||
elif t == NodeDevice.CAPABILITY_TYPE_USBBUS:
|
||||
return USBBus
|
||||
|
Loading…
x
Reference in New Issue
Block a user