[PATCH] Create additional functionalities.

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

 



* __init__.py: (getRaidSet): New function.  Will return one set object.
* __init__.py: (getMemFromRaidSet): New function.  Will return the
               member object for the specified member.
* __init__.py: (getRaidSetFromRelatedMem): New function.  Given a device
               (uuid, major/minor or name) we return the set that
               contains it.
* device.py: (compare_tables): cannot use zip's iterator as we would
             need to call "next" inside the function (to get the device
             arguemnt from table string).
---
 __init__.py |   64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 device.py   |   10 ++++----
 2 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/__init__.py b/__init__.py
index 9911940..90bd229 100644
--- a/__init__.py
+++ b/__init__.py
@@ -201,6 +201,18 @@ def getRaidSets(*disks):
             rsList.append(set)
     return rsList
 
+def getRaidSet(name, prefix="/dev/mapper"):
+    """Get a raid set by name."""
+    c = dmraid.context()
+    for rs in c.get_raidsets([]):
+        if rs.name == name:
+            set = RaidSet(rs, prefix=prefix)
+            # FIXME: should raise some type of error if this is false.
+            # FIXME: should we do something different when degraded?
+            if set.valid:
+                return set
+    return None
+
 def getMap(uuid = None, major = None, minor = None, name = None):
     """ Return a map that matches the given parameters.
 
@@ -308,6 +320,58 @@ def getDmNodeFromName(name):
 
     return None
 
+def getMemFromRaidSet(rs, uuid=None, major=None, minor=None, name=None):
+    """ Retrieve the object of specified member of RaidSet rs.
+
+    uuid and name are strings.  major and minor are converted to long before
+    being compared.  name is the dev name without the path.
+
+    Returns an Ojbect.
+    Returns None on failure.
+    """
+    if not isinstance(rs, RaidSet):
+        return None
+
+    kwargs = {"uuid":uuid, "name":name, "major":major, "minor":minor}
+    for mem in rs.members:
+        # We can actually come across two types of objects: RaidDev and RaidSet
+        if isinstance(mem, RaidSet):
+            if (mem.name is not None and mem.name == name) or \
+                    (mem.bdev != None and # Intermediate rs's dont have bdev
+                     mem.bdev.major != None and mem.bdev.major == major and \
+                     mem.bdev.minor != None and mem.bdev.minor == minor) or \
+                    (mem.map.uuid != None and mem.map.uuid == uuid):
+                return mem
+            ret = getMemFromRaidSet(mem, **kwargs)
+            if ret != None:
+                return ret
+
+        elif isinstance(mem, RaidDev):
+             if (mem.devpath is not None and mem.devpath == name) or \
+                    (mem.bdev.major != None and mem.bdev.major == major and \
+                     mem.bdev.minor != None and mem.bdev.minor == minor):
+                return mem
+        else:
+            # We will fail if we recieve something we don't expect
+            return None
+
+    return None
+
+def getRaidSetFromRelatedMem(uuid=None, major=None, minor=None, name=None):
+    """ Retrieve the set name of the related device.
+
+    uuid and name are strings.  major and minor are converted to long before
+    being compared.  name is the dev name without the path.
+
+    Returns a string.
+    Returns None if no set is related to the specified device.
+    """
+    kwargs = {"uuid":uuid, "name":name, "major":major, "minor":minor}
+    for rs in getRaidSets():
+        if  getMemFromRaidSet(rs, **kwargs) != None:
+            return rs
+
+    return None
 
 __all__ = [ "dm", "dmraid", "BlockDev" ]
 
diff --git a/device.py b/device.py
index 8a6d0d9..32be96b 100644
--- a/device.py
+++ b/device.py
@@ -65,12 +65,12 @@ def map_dev(path):
 # The tables will be considered the same if for every row, with everything else
 # being the same, they contain the same sets of devices.
 def compare_tables(t1, t2):
-    for table1, table2 in zip(t1, t2):
-        table1 = str(table1).strip().split(' ')
-        table2 = str(table2).strip().split(' ')
-        table1sets = []
-        table2sets = []
+    table1 = str(t1).strip().split(' ')
+    table2 = str(t2).strip().split(' ')
+    table1sets = []
+    table2sets = []
 
+    for i in range(len(table1)):
         # We do this to avoid the index out of range exception
         if len(table1) != len(table2):
             return False
-- 
1.6.0.6

_______________________________________________
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