From dc09c3cfdf6297df662657ed9c51e2ca980df2df Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 27 Oct 2009 12:24:19 +0900
Subject: [PATCH] Make gnt-node list-storage more standard
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch adds support for the -o+field,… format that the other list
commands accept and changes the format of the allocatable field from
simply str(bool) to Y/N.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 scripts/gnt-node | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/scripts/gnt-node b/scripts/gnt-node
index 68be35991..9febd421e 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -494,9 +494,11 @@ def ListStorage(opts, args):
       ],
   }
 
+  def_fields = ["node"] + default_fields[storage_type]
   if opts.output is None:
-    selected_fields = ["node"]
-    selected_fields.extend(default_fields[storage_type])
+    selected_fields = def_fields
+  elif opts.output.startswith("+"):
+    selected_fields = def_fields + opts.output[1:].split(",")
   else:
     selected_fields = opts.output.split(",")
 
@@ -520,6 +522,17 @@ def ListStorage(opts, args):
   unitfields = [constants.SF_SIZE, constants.SF_USED, constants.SF_FREE]
   numfields = [constants.SF_SIZE, constants.SF_USED, constants.SF_FREE]
 
+  # change raw values to nicer strings
+  for row in output:
+    for idx, field in enumerate(selected_fields):
+      val = row[idx]
+      if field == constants.SF_ALLOCATABLE:
+        if val:
+          val = "Y"
+        else:
+          val = "N"
+      row[idx] = str(val)
+
   data = GenerateTable(separator=opts.separator, headers=headers,
                        fields=selected_fields, unitfields=unitfields,
                        numfields=numfields, data=output, units=opts.units)
-- 
GitLab