From 503574ec72f504e3bde8fa584df4184f2c0a0de5 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 20 Dec 2012 12:00:44 +0100
Subject: [PATCH] Format network field "group_list" in client

The field is now a list of tuples containing the group name, mode and
link.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/client/gnt_network.py | 7 +++++--
 lib/cmdlib.py             | 7 ++++---
 lib/query.py              | 5 +++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/client/gnt_network.py b/lib/client/gnt_network.py
index 714658214..1b0cc567f 100644
--- a/lib/client/gnt_network.py
+++ b/lib/client/gnt_network.py
@@ -153,10 +153,13 @@ def ListNetworks(opts, args):
   """
   desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
   fmtoverride = {
-    "group_list": (",".join, False),
+    "group_list":
+      (lambda data: utils.CommaJoin("%s (%s, %s)" % (name, mode, link)
+                                    for (name, mode, link) in data),
+       False),
     "inst_list": (",".join, False),
     "tags": (",".join, False),
-  }
+    }
 
   return GenericList(constants.QR_NETWORK, desired_fields, args, None,
                      opts.separator, not opts.no_headers,
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index bdc26dae4..4a7e66375 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -16225,9 +16225,10 @@ class _NetworkQuery(_QueryBase):
         for net_uuid in group.networks.keys():
           if net_uuid in network_to_groups:
             netparams = group.networks[net_uuid]
-            mode = netparams[constants.NIC_MODE]
-            link = netparams[constants.NIC_LINK]
-            info = group.name + "(" + mode + ", " + link + ")"
+
+            info = (group.name, netparams[constants.NIC_MODE],
+                    netparams[constants.NIC_LINK])
+
             network_to_groups[net_uuid].append(info)
 
             if do_instances:
diff --git a/lib/query.py b/lib/query.py
index 396ff808a..c7f8fa9fa 100644
--- a/lib/query.py
+++ b/lib/query.py
@@ -2556,8 +2556,9 @@ def _BuildNetworkFields():
   fields.extend([
     (_MakeField("group_cnt", "NodeGroups", QFT_NUMBER, "Number of nodegroups"),
      NETQ_GROUP, 0, _GetLength(network_to_groups)),
-    (_MakeField("group_list", "GroupList", QFT_OTHER, "List of nodegroups"),
-     NETQ_GROUP, 0, _GetSortedList(network_to_groups)),
+    (_MakeField("group_list", "GroupList", QFT_OTHER,
+     "List of nodegroups (group name, NIC mode, NIC link)"),
+     NETQ_GROUP, 0, lambda ctx, network: network_to_groups(ctx)[network.uuid]),
     ])
 
   # Add fields for instances
-- 
GitLab