Export node group data in iallocator
authorIustin Pop <iustin@google.com>
Mon, 25 Oct 2010 11:11:08 +0000 (13:11 +0200)
committerIustin Pop <iustin@google.com>
Tue, 26 Oct 2010 09:47:24 +0000 (11:47 +0200)
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

doc/iallocator.rst
lib/cmdlib.py
lib/config.py

index de2759c..248a9df 100644 (file)
@@ -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
index e881e67..4496f16 100644 (file)
@@ -10200,6 +10200,8 @@ 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)
@@ -10207,6 +10209,16 @@ class IAllocator(object):
     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.
 
index 21a362a..156f1de 100644 (file)
@@ -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.