[PATCH 1/5] Split out common lvm parsing code.
David Lehman
dlehman at redhat.com
Fri Mar 28 20:32:50 UTC 2014
---
blivet/devicelibs/lvm.py | 50 ++++++++++++++++++++----------------------------
1 file changed, 21 insertions(+), 29 deletions(-)
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index bc6d563..67e8fe2 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -273,6 +273,22 @@ def pvmove(source, dest=None):
except LVMError as msg:
raise LVMError("pvmove failed for %s->%s: %s" % (source, dest, msg))
+def parse_lvm_vars(line):
+ info = {}
+ for var in line.split():
+ (name, equals, value) = var.partition("=")
+ if not equals:
+ continue
+
+ if "," in value:
+ val = value.strip().split(",")
+ else:
+ val = value.strip()
+
+ info[name] = val
+
+ return info
+
def pvinfo(device):
"""
If the PV was created with '--metadacopies 0', lvm will do some
@@ -289,20 +305,10 @@ def pvinfo(device):
_getConfigArgs(read_only_locking=True) + \
[device]
- rc = util.capture_output(["lvm"] + args)
- _vars = rc.split()
- info = {}
- for var in _vars:
- (name, equals, value) = var.partition("=")
- if not equals:
- continue
-
- if "," in value:
- val = value.strip().split(",")
- else:
- val = value.strip()
-
- info[name] = val
+ buf = util.capture_output(["lvm"] + args)
+ info = parse_lvm_vars(buf)
+ if len(info.keys()) != 10:
+ raise LVMError(_("pvinfo failed for %s" % device))
return info
@@ -394,22 +400,8 @@ def vginfo(vg_name):
"-o", "uuid,size,free,extent_size,extent_count,free_count,pv_count"] + \
_getConfigArgs(read_only_locking=True) + [vg_name]
- # TODO: make this a common code reused many functions
buf = util.capture_output(["lvm"] + args)
- fields = buf.split()
- info = {}
- for field in fields:
- (name, equals, value) = field.partition("=")
- if not equals:
- continue
-
- if "," in value:
- val = value.strip().split(",")
- else:
- val = value.strip()
-
- info[name] = val
-
+ info = parse_lvm_vars(buf)
if len(info.keys()) != 7:
raise LVMError(_("vginfo failed for %s" % vg_name))
--
1.9.0
More information about the anaconda-patches
mailing list