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

[PATCH 05/14] Add a method to get the bus/interconnect from udev and store it on devices.



---
 storage/devices.py    |    8 +++++---
 storage/devicetree.py |    3 ++-
 storage/udev.py       |    4 ++++
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index 75f9107..e61591c 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -422,7 +422,7 @@ class StorageDevice(Device):
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None,
                  sysfsPath='', parents=None, exists=None, serial=None,
-                 vendor=""):
+                 vendor="", bus=""):
         """ Create a StorageDevice instance.
 
             Arguments:
@@ -454,6 +454,7 @@ class StorageDevice(Device):
         self.exists = exists
         self.serial = serial
         self.vendor = vendor
+        self.bus = bus
 
         self.protected = False
 
@@ -718,7 +719,7 @@ class DiskDevice(StorageDevice):
 
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None, sysfsPath='',
-                 parents=None, serial=None, vendor=""):
+                 parents=None, serial=None, vendor="", bus=""):
         """ Create a DiskDevice instance.
 
             Arguments:
@@ -736,6 +737,7 @@ class DiskDevice(StorageDevice):
                 removable -- whether or not this is a removable device
                 serial -- the ID_SERIAL_SHORT for this device
                 vendor -- the manufacturer of this Device
+                bus -- the interconnect this device uses
 
 
             DiskDevices always exist.
@@ -743,7 +745,7 @@ class DiskDevice(StorageDevice):
         StorageDevice.__init__(self, device, format=format, size=size,
                                major=major, minor=minor, exists=True,
                                sysfsPath=sysfsPath, parents=parents,
-                               serial=serial, vendor=vendor)
+                               serial=serial, vendor=vendor, bus=bus)
 
     def __str__(self):
         s = StorageDevice.__str__(self)
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 6090dd3..a5a59e7 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -1166,6 +1166,7 @@ class DeviceTree(object):
         uuid = udev_device_get_uuid(info)
         sysfs_path = udev_device_get_sysfs_path(info)
         serial = udev_device_get_serial(info)
+        bus = udev_device_get_bus(info)
 
         try:
             # udev doesn't always provide a vendor.
@@ -1223,7 +1224,7 @@ class DeviceTree(object):
         device = diskType(name, serial=serial, vendor=vendor,
                           major=udev_device_get_major(info),
                           minor=udev_device_get_minor(info),
-                          sysfsPath=sysfs_path, **kwargs)
+                          sysfsPath=sysfs_path, bus=bus, **kwargs)
         self._addDevice(device)
         return device
 
diff --git a/storage/udev.py b/storage/udev.py
index aa131b4..4ea9a94 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -258,6 +258,10 @@ def udev_device_get_vendor(udev_info):
     """ Get the vendor of the device as reported by udev. """
     return udev_info.get("ID_VENDOR_FROM_DATABASE", udev_info.get("ID_VENDOR"))
 
+def udev_device_get_bus(udev_info):
+    """ Get the bus a device is connected to the system by. """
+    return udev_info.get("ID_BUS").upper()
+
 def udev_device_get_sysfs_path(info):
     return info['sysfs_path']
 
-- 
1.6.5.1


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