From edf45a43a2dd6142de1ca407b9e344b427c8e4c3 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Fri, 10 Jul 2009 09:58:35 -1000 Subject: Add deviceNameToDiskByPath(). 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 file changed, 17 insertions(+) (limited to 'storage') diff --git a/storage/devices.py b/storage/devices.py index e2367105f..d8b437800 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. -- cgit