From 622444e577084f8406a988735129085d2f1645b2 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 25 Oct 2010 13:11:08 +0200
Subject: [PATCH] Export node group data in iallocator

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 doc/iallocator.rst |  8 ++++++++
 lib/cmdlib.py      | 12 ++++++++++++
 lib/config.py      |  7 +++++++
 3 files changed, 27 insertions(+)

diff --git a/doc/iallocator.rst b/doc/iallocator.rst
index de2759c1e..248a9dfc6 100644
--- a/doc/iallocator.rst
+++ b/doc/iallocator.rst
@@ -171,6 +171,14 @@ request
   nodes
     the names of the nodes to be evacuated
 
+nodegroups
+  a dictionary with the data for the cluster's node groups; it is keyed
+  on the group UUID, and the values are a dictionary with the following
+  keys:
+
+  name
+    the node group name
+
 instances
   a dictionary with the data for the current existing instance on the
   cluster, indexed by instance name; the contents are similar to the
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index e881e6745..4496f161c 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -10200,12 +10200,24 @@ class IAllocator(object):
       self.rpc.call_all_instances_info(node_list,
                                        cluster_info.enabled_hypervisors)
 
+    data["nodegroups"] = self._ComputeNodeGroupData(cfg)
+
     data["nodes"] = self._ComputeNodeData(cfg, node_data, node_iinfo, i_list)
 
     data["instances"] = self._ComputeInstanceData(cluster_info, i_list)
 
     self.in_data = data
 
+  @staticmethod
+  def _ComputeNodeGroupData(cfg):
+    """Compute node groups data.
+
+    """
+    ng = {}
+    for guuid, gdata in cfg.GetAllNodeGroupsInfo().items():
+      ng[guuid] = { "name": gdata.name }
+    return ng
+
   @staticmethod
   def _ComputeNodeData(cfg, node_data, node_iinfo, i_list):
     """Compute global node data.
diff --git a/lib/config.py b/lib/config.py
index 21a362ae2..156f1deab 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -876,6 +876,13 @@ class ConfigWriter:
         return nodegroup.uuid
     raise errors.OpPrereqError("Nodegroup '%s' not found", target)
 
+  @locking.ssynchronized(_config_lock, shared=1)
+  def GetAllNodeGroupsInfo(self):
+    """Get the configuration of all node groups.
+
+    """
+    return dict(self._config_data.nodegroups)
+
   @locking.ssynchronized(_config_lock)
   def AddInstance(self, instance, ec_id):
     """Add an instance to the config.
-- 
GitLab