[master][PATCH] Make vginfo work the same way as pvinfo and other LVM functions
Vratislav Podzimek
vpodzime at redhat.com
Mon Mar 10 16:41:29 UTC 2014
All the other LVM devicelib functions return a dictionary.
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
blivet/devicelibs/lvm.py | 27 ++++++++++++++++++++-------
blivet/devices.py | 4 ++--
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/blivet/devicelibs/lvm.py b/blivet/devicelibs/lvm.py
index b824398..a797710 100644
--- a/blivet/devicelibs/lvm.py
+++ b/blivet/devicelibs/lvm.py
@@ -352,15 +352,28 @@ def vgreduce(vg_name, pv_list, rm=False):
raise LVMError("vgreduce failed for %s: %s" % (vg_name, msg))
def vginfo(vg_name):
- args = ["vgs", "--noheadings", "--nosuffix"] + \
- ["--units", "m"] + \
- ["-o", "uuid,size,free,extent_size,extent_count,free_count,pv_count"] + \
- _getConfigArgs(read_only_locking=True) + \
- [vg_name]
+ args = ["vgs", "--noheadings", "--nosuffix", "--nameprefixes", "--unquoted",
+ "--units", "m",
+ "-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)
- info = buf.split()
- if len(info) != 7:
+ 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
+
+ if len(info.keys()) != 7:
raise LVMError(_("vginfo failed for %s" % vg_name))
return info
diff --git a/blivet/devices.py b/blivet/devices.py
index fb24b10..9e6efb4 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -2724,8 +2724,8 @@ class LVMLogicalVolumeDevice(DMDevice):
# nothing more can be done, we don't know the VG's free space
return
- extent_size = Size(spec=vg_info[3] + "MiB")
- extents_free = int(vg_info[5])
+ extent_size = Size(spec=vg_info["LVM2_VG_EXTENT_SIZE"] + "MiB")
+ extents_free = int(vg_info["LVM2_VG_FREE_COUNT"])
can_use = extent_size * extents_free
if self.size > can_use:
--
1.8.5.3
More information about the anaconda-patches
mailing list