[virt-tools-list] [PATCH 03/12] nodedev: add DevNode children and helper

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Tue Feb 21 13:00:53 UTC 2017


From: Marc-André Lureau <marcandre.lureau at redhat.com>

<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 at redhat.com>
---
 tests/nodedev.py     |  3 +++
 tests/testdriver.xml |  1 +
 virtinst/nodedev.py  | 20 +++++++++++++++++++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/tests/nodedev.py b/tests/nodedev.py
index 1a69c823..0d214afe 100644
--- a/tests/nodedev.py
+++ b/tests/nodedev.py
@@ -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",
diff --git a/tests/testdriver.xml b/tests/testdriver.xml
index c5cdac9a..daf74f26 100644
--- a/tests/testdriver.xml
+++ b/tests/testdriver.xml
@@ -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>
diff --git a/virtinst/nodedev.py b/virtinst/nodedev.py
index 6147d70d..07ffe01e 100644
--- a/virtinst/nodedev.py
+++ b/virtinst/nodedev.py
@@ -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):
         """
-- 
2.11.0.295.gd7dffce1c.dirty




More information about the virt-tools-list mailing list