From 0fff97e93fdcd87968499a02b4881e7102db8508 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Wed, 3 Dec 2008 17:23:08 +0000
Subject: [PATCH] LUAddNode: Auto-make master candidates

When a node is added, if there are not enough master candidates, we'll
automatically promote it.

Reviewed-by: imsnah
---
 lib/cmdlib.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index fbb4cb9a2..8771f66ff 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1950,9 +1950,16 @@ class LUAddNode(LogicalUnit):
         raise errors.OpPrereqError("Node secondary ip not reachable by TCP"
                                    " based ping to noded port")
 
+    cp_size = self.cfg.GetClusterInfo().candidate_pool_size
+    node_info = self.cfg.GetAllNodesInfo().values()
+    num_candidates = len([n for n in node_info
+                          if n.master_candidate])
+    master_candidate = num_candidates < cp_size
+
     self.new_node = objects.Node(name=node,
                                  primary_ip=primary_ip,
-                                 secondary_ip=secondary_ip)
+                                 secondary_ip=secondary_ip,
+                                 master_candidate=master_candidate)
 
   def Exec(self, feedback_fn):
     """Adds the new node to the cluster.
-- 
GitLab