[blivet:master/rhel7 5/9] Make a procedure for reading an array's state from its file (#1090009)
mulhern
amulhern at redhat.com
Thu Dec 11 22:29:25 UTC 2014
Related: rhbz#1090009
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devicelibs/mdraid.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index 1db090d..8d1d3f6 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -423,3 +423,21 @@ def mduuid_from_canonical(a_uuid):
CHUNK_LEN = 8
return ":".join(a_uuid[n:n+CHUNK_LEN] for n in range(0, NUM_DIGITS, CHUNK_LEN))
+
+def md_array_state(sysfs_path):
+ """ Get the state of an array by directly reading its array_state file.
+
+ :param str sysfs_path: sysfs device path
+
+ :returns: a string indicating the array state, or None
+ :rtype: str or NoneType
+ """
+ state_file = os.path.join(sysfs_path, "md/array_state")
+
+ state = None
+ try:
+ with open(state_file, "r") as sf:
+ state = sf.read().strip()
+ except IOError:
+ pass
+ return state
--
1.9.3
More information about the anaconda-patches
mailing list