From 4edc512c5ea833c8d40f84b2234f6eba09d22dbe Mon Sep 17 00:00:00 2001
From: Adeodato Simo <dato@google.com>
Date: Thu, 2 Dec 2010 16:56:36 +0000
Subject: [PATCH] Expose new node group attributes in CLI and RAPI

Signed-off-by: Adeodato Simo <dato@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/client/gnt_group.py | 12 ++++++++++--
 lib/cmdlib.py           |  2 +-
 lib/rapi/rlib2.py       |  3 ++-
 man/gnt-group.rst       | 16 ++++++++++++++++
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/lib/client/gnt_group.py b/lib/client/gnt_group.py
index 2bdc193ea..5477b1105 100644
--- a/lib/client/gnt_group.py
+++ b/lib/client/gnt_group.py
@@ -26,6 +26,7 @@
 
 from ganeti.cli import *
 from ganeti import compat
+from ganeti import utils
 
 
 #: default list of fields for L{ListGroups}
@@ -37,6 +38,7 @@ _LIST_HEADERS = {
   "name": "Group", "uuid": "UUID",
   "node_cnt": "Nodes", "node_list": "NodeList",
   "pinst_cnt": "Instances", "pinst_list": "InstanceList",
+  "ctime": "CTime", "mtime": "MTime", "serial_no": "SerialNo",
 }
 
 
@@ -59,8 +61,9 @@ def ListGroups(opts, args):
   else:
     headers = _LIST_HEADERS
 
-  int_type_fields = frozenset(["node_cnt", "pinst_cnt"])
+  int_type_fields = frozenset(["node_cnt", "pinst_cnt", "serial_no"])
   list_type_fields = frozenset(["node_list", "pinst_list"])
+  date_type_fields = frozenset(["mtime", "ctime"])
 
   for row in output:
     for idx, field in enumerate(desired_fields):
@@ -70,6 +73,8 @@ def ListGroups(opts, args):
         val = ",".join(val)
       elif opts.roman_integers and field in int_type_fields:
         val = compat.TryToRoman(val)
+      elif field in date_type_fields:
+        val = utils.FormatTime(val)
       elif val is None:
         val = "?"
 
@@ -88,7 +93,10 @@ commands = {
   "list": (
     ListGroups, ARGS_MANY_GROUPS,
     [NOHDR_OPT, SEP_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
-    "[<group_name>...]", "Lists the node groups in the cluster."),
+    "[<group_name>...]",
+    "Lists the node groups in the cluster. The available fields are (see"
+    " the man page for details): %s. The default list is (in order): %s." %
+    (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
 }
 
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 97316a247..9505e19a2 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -10311,7 +10311,7 @@ class LUQueryGroups(NoHooksLU):
 
   _FIELDS_DYNAMIC = utils.FieldSet()
 
-  _SIMPLE_FIELDS = ["name", "uuid"]
+  _SIMPLE_FIELDS = ["name", "uuid", "ctime", "mtime", "serial_no"]
 
   _FIELDS_STATIC = utils.FieldSet(
       "node_cnt", "node_list", "pinst_cnt", "pinst_list", *_SIMPLE_FIELDS)
diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py
index 8f5dc3869..39514a0e8 100644
--- a/lib/rapi/rlib2.py
+++ b/lib/rapi/rlib2.py
@@ -75,7 +75,8 @@ N_FIELDS = ["name", "offline", "master_candidate", "drained",
 
 G_FIELDS = ["name", "uuid",
             "node_cnt", "node_list",
-            ]
+            "ctime", "mtime", "serial_no",
+            ]  # "tags" is missing to be able to use _COMMON_FIELDS here.
 
 _NR_DRAINED = "drained"
 _NR_MASTER_CANDIATE = "master-candidate"
diff --git a/man/gnt-group.rst b/man/gnt-group.rst
index 6c8641bb1..086d6489a 100644
--- a/man/gnt-group.rst
+++ b/man/gnt-group.rst
@@ -60,5 +60,21 @@ pinst_cnt
 pinst_list
     the list of primary instances in the group
 
+ctime
+    the creation time of the group; note that this field contains spaces
+    and as such it's harder to parse
+
+    if this attribute is not present (e.g. when upgrading from older
+    versions), then "N/A" will be shown instead
+
+mtime
+    the last modification time of the group; note that this field
+    contains spaces and as such it's harder to parse
+
+serial_no
+    the so called 'serial number' of the group; this is a numeric field
+    that is incremented each time the node is modified, and it can be
+    used to detect modifications
+
 If no group names are given, then all groups are included. Otherwise,
 only the named groups will be listed.
-- 
GitLab