[PATCH] Add deviceNameToDiskByPath().

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function takes a device name (e.g., sda) and returns the link name
that it matches in /dev/disk/by-path.  Used to help people with many
similar named devices (hundreds of DASDs, for example).
---
 storage/devices.py |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index b46479b..a70c667 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -143,6 +143,23 @@ def devicePathToName(devicePath):
     return name
 
 
+def deviceNameToDiskByPath(deviceName=None):
+    bypath = '/dev/disk/by-path'
+
+    if not deviceName:
+        return ""
+
+    if not os.path.isdir(bypath):
+        return ""
+
+    for path in os.listdir(bypath):
+        target = os.path.basename(os.readlink(bypath + '/' + path))
+        if target == deviceName:
+            return path
+
+    return ""
+
+
 class Device(object):
     """ A generic device.
 
-- 
1.6.3.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux