]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: lvm add a parser for the delimeted output in the CLI 17123/head
authorAlfredo Deza <adeza@redhat.com>
Fri, 18 Aug 2017 21:05:45 +0000 (17:05 -0400)
committerAlfredo Deza <adeza@redhat.com>
Mon, 21 Aug 2017 23:17:02 +0000 (19:17 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/devices/lvm/api.py

index f63a1e95c598025e0716c6f5b174d3a922220bea..944a4343dad438a7ffd1ffd88cd6d50408fd9972 100644 (file)
@@ -7,6 +7,41 @@ from ceph_volume import process
 from ceph_volume.exceptions import MultipleLVsError, MultipleVGsError
 
 
+def _output_parser(output, fields):
+    """
+    Newer versions of LVM allow ``--reportformat=json``, but older versions,
+    like the one included in Xenial do not. LVM has the ability to filter and
+    format its output so we assume the output will be in a format this parser
+    can handle (using ',' as a delimiter)
+
+    :param fields: A string, possibly using ',' to group many items, as it
+                   would be used on the CLI
+    :param output: The CLI output from the LVM call
+    """
+    field_items = fields.split(',')
+    report = []
+    for line in output:
+        # clear the leading/trailing whitespace
+        line = line.strip()
+
+        # remove the extra '"' in each field
+        line = line.replace('"', '')
+
+        # prevent moving forward with empty contents
+        if not line:
+            continue
+
+        # spliting on ';' because that is what the lvm call uses as
+        # '--separator'
+        output_items = [i.strip() for i in line.split(';')]
+        # map the output to the fiels
+        report.append(
+            dict(zip(field_items, output_items))
+        )
+
+    return report
+
+
 def parse_tags(lv_tags):
     """
     Return a dictionary mapping of all the tags associated with