mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
nodedev: add DevNode children and helper
<devnode> have been proposed for libvirt 3.1, it provides device /dev/ path when available. The get_devnode() helper will return the by-path/ path preferably, as they should be stable. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
806bbbb4ea
commit
a861629f0c
@ -181,6 +181,9 @@ class TestNodeDev(unittest.TestCase):
|
||||
devname = "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685"
|
||||
vals = {"name": "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685",
|
||||
"parent": "pci_8086_27c0_scsi_host_scsi_device_lun0",
|
||||
"devnodes": [
|
||||
{"path": "/dev/sda", "node_type": "dev"}
|
||||
],
|
||||
"device_type": NodeDevice.CAPABILITY_TYPE_STORAGE,
|
||||
"block": "/dev/sda", "bus": "scsi", "drive_type": "disk",
|
||||
"model": "WDC WD1600AAJS-2", "vendor": "ATA",
|
||||
|
@ -2974,6 +2974,7 @@ ba</description>
|
||||
<device>
|
||||
<name>storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685</name>
|
||||
<parent>pci_8086_27c0_scsi_host_scsi_device_lun0</parent>
|
||||
<devnode type='dev'>/dev/sda</devnode>
|
||||
<capability type='storage'>
|
||||
<block>/dev/sda</block>
|
||||
<bus>scsi</bus>
|
||||
|
@ -18,8 +18,9 @@
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from .xmlbuilder import XMLBuilder, XMLProperty
|
||||
from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
|
||||
|
||||
|
||||
def _compare_int(nodedev_val, hostdev_val):
|
||||
@ -37,6 +38,13 @@ def _compare_int(nodedev_val, hostdev_val):
|
||||
return (nodedev_val == hostdev_val or hostdev_val == -1)
|
||||
|
||||
|
||||
class DevNode(XMLBuilder):
|
||||
_XML_ROOT_NAME = "devnode"
|
||||
|
||||
node_type = XMLProperty("./@type")
|
||||
path = XMLProperty(".")
|
||||
|
||||
|
||||
class NodeDevice(XMLBuilder):
|
||||
CAPABILITY_TYPE_SYSTEM = "system"
|
||||
CAPABILITY_TYPE_NET = "net"
|
||||
@ -104,6 +112,16 @@ class NodeDevice(XMLBuilder):
|
||||
name = XMLProperty("./name")
|
||||
parent = XMLProperty("./parent")
|
||||
device_type = XMLProperty("./capability/@type")
|
||||
devnodes = XMLChildProperty(DevNode)
|
||||
|
||||
def get_devnode(self, parent="by-path"):
|
||||
for d in self.devnodes:
|
||||
paths = d.path.split(os.sep)
|
||||
if len(paths) > 2 and paths[-2] == parent:
|
||||
return d
|
||||
if len(self.devnodes) > 0:
|
||||
return self.devnodes[0]
|
||||
return None
|
||||
|
||||
def pretty_name(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user