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:
Marc-André Lureau 2017-02-21 17:00:53 +04:00 committed by Cole Robinson
parent 806bbbb4ea
commit a861629f0c
3 changed files with 23 additions and 1 deletions

View File

@ -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",

View File

@ -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>

View File

@ -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):
"""