[PATCH 08/19] Make all StorageDevice-s support .vendor and .model

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

 



Not everything has one, but this makes them all at least show "None"
instead of having to do the hasattr dance.  Also, it now normally gets
the info from udev rather than using parted's concatenated version
(which fixes some minor UI problems as well as making it available at
more places.)

Also add a correct "model" method to MultipathDevice - we want to
display the model for the underlying disk device, not "linux device
mapper device" or whatnot.
---
 storage/devices.py    |   52 ++++++++++++++++++++++++++++++++++++++----------
 storage/devicetree.py |    8 +++++-
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index 6b19fd8..8d74fa7 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -432,7 +432,7 @@ class StorageDevice(Device):
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None,
                  sysfsPath='', parents=None, exists=None, serial=None,
-                 vendor="", bus=""):
+                 vendor="", model="", bus=""):
         """ Create a StorageDevice instance.
 
             Arguments:
@@ -447,6 +447,10 @@ class StorageDevice(Device):
                 sysfsPath -- sysfs device path
                 format -- a DeviceFormat instance
                 parents -- a list of required Device instances
+                serial -- the ID_SERIAL_SHORT for this device
+                vendor -- the manufacturer of this Device
+                model -- manufacturer's device model string
+                bus -- the interconnect this device uses
 
         """
         # allow specification of individual parents
@@ -462,8 +466,9 @@ class StorageDevice(Device):
         self.major = numeric_type(major)
         self.minor = numeric_type(minor)
         self.sysfsPath = sysfsPath
-        self.serial = serial
-        self.vendor = vendor
+        self._serial = serial
+        self._vendor = vendor
+        self._model = model
         self.bus = bus
 
         self.protected = False
@@ -737,6 +742,19 @@ class StorageDevice(Device):
     def partitioned(self):
         return self.format.type == "disklabel" and self.partitionable
 
+    @property
+    def serial(self):
+        return self._serial
+
+    @property
+    def model(self):
+        if not self._model:
+            self._model = getattr(self.partedDevice, "model", None)
+        return self._model
+
+    @property
+    def vendor(self):
+        return self._vendor
 
 class DiskDevice(StorageDevice):
     """ A disk """
@@ -746,7 +764,7 @@ class DiskDevice(StorageDevice):
 
     def __init__(self, device, format=None,
                  size=None, major=None, minor=None, sysfsPath='',
-                 parents=None, serial=None, vendor="", bus="",
+                 parents=None, serial=None, vendor="", model="", bus="",
                  exists=True):
         """ Create a DiskDevice instance.
 
@@ -765,6 +783,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
+                model -- manufacturer's device model string
                 bus -- the interconnect this device uses
 
 
@@ -773,7 +792,8 @@ class DiskDevice(StorageDevice):
         StorageDevice.__init__(self, device, format=format, size=size,
                                major=major, minor=minor, exists=exists,
                                sysfsPath=sysfsPath, parents=parents,
-                               serial=serial, vendor=vendor, bus=bus)
+                               serial=serial, model=model,
+                               vendor=vendor, bus=bus)
 
     def __str__(self):
         s = StorageDevice.__str__(self)
@@ -792,10 +812,6 @@ class DiskDevice(StorageDevice):
         return self.partedDevice.getSize() != 0
 
     @property
-    def model(self):
-        return getattr(self.partedDevice, "model", None)
-
-    @property
     def description(self):
         return self.model
 
@@ -2969,6 +2985,18 @@ class MultipathDevice(DMDevice):
         return ":".join(ret)
 
     @property
+    def model(self):
+        if not self.parents:
+            return ""
+        return self.parents[0].model
+
+    @property
+    def vendor(self):
+        if not self.parents:
+            return ""
+        return self.parents[0].vendor
+
+    @property
     def description(self):
         return "WWID %s" % (self.wwid,)
 
@@ -3245,10 +3273,12 @@ class OpticalDevice(StorageDevice):
     _type = "cdrom"
 
     def __init__(self, name, major=None, minor=None, exists=None,
-                 format=None, parents=None, sysfsPath=''):
+                 format=None, parents=None, sysfsPath='', vendor="",
+                 model=""):
         StorageDevice.__init__(self, name, format=format,
                                major=major, minor=minor, exists=True,
-                               parents=parents, sysfsPath=sysfsPath)
+                               parents=parents, sysfsPath=sysfsPath,
+                               vendor=vendor, model=model)
 
     @property
     def mediaPresent(self):
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 0059a20..1c241ab 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -1179,7 +1179,9 @@ class DeviceTree(object):
         device = OpticalDevice(udev_device_get_name(info),
                                major=udev_device_get_major(info),
                                minor=udev_device_get_minor(info),
-                               sysfsPath=udev_device_get_sysfs_path(info))
+                               sysfsPath=udev_device_get_sysfs_path(info),
+                               vendor=udev_device_get_vendor(info),
+                               model=udev_device_get_model(info))
         self._addDevice(device)
         return device
 
@@ -1204,7 +1206,9 @@ class DeviceTree(object):
                             major=udev_device_get_major(info),
                             minor=udev_device_get_minor(info),
                             sysfsPath=sysfs_path, exists=True,
-                            serial=udev_device_get_serial(info))
+                            serial=udev_device_get_serial(info),
+                            vendor=udev_device_get_vendor(info),
+                            model=udev_device_get_model(info))
             self._addDevice(device)
         elif udev_device_is_dm(info) and \
                devicelibs.dm.dm_is_multipath(info):
-- 
1.6.5.2

_______________________________________________
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