From 4c61d8945063934463aa57eb3f2ede70200143a5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 9 Mar 2010 13:21:54 +0100
Subject: [PATCH] Add the auto_promote option to cli and gnt-node

This allows one to cleanly set a node offline and promote as needed
other nodes.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cli.py        |  6 ++++++
 man/gnt-node.sgml | 14 ++++++++++----
 scripts/gnt-node  |  6 ++++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index 226334d6b..5f8a9ed53 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -45,6 +45,7 @@ __all__ = [
   # Command line options
   "ALLOCATABLE_OPT",
   "ALL_OPT",
+  "AUTO_PROMOTE_OPT",
   "AUTO_REPLACE_OPT",
   "BACKEND_OPT",
   "CLEANUP_OPT",
@@ -708,6 +709,11 @@ ON_SECONDARY_OPT = cli_option("-s", "--on-secondary", dest="on_secondary",
                               help="Replace the disk(s) on the secondary"
                               " node (only for the drbd template)")
 
+AUTO_PROMOTE_OPT = cli_option("--auto-promote", dest="auto_promote",
+                              default=False, action="store_true",
+                              help="Lock all nodes and auto-promote as needed"
+                              " to MC status")
+
 AUTO_REPLACE_OPT = cli_option("-a", "--auto", dest="auto",
                               default=False, action="store_true",
                               help="Automatically replace faulty disks"
diff --git a/man/gnt-node.sgml b/man/gnt-node.sgml
index 9f1c8fbf2..27a4253be 100644
--- a/man/gnt-node.sgml
+++ b/man/gnt-node.sgml
@@ -596,6 +596,7 @@
         <arg>--master-candidate=<option>yes|no</option></arg>
         <arg>--drained=<option>yes|no</option></arg>
         <arg>--offline=<option>yes|no</option></arg>
+        <arg>--auto-promote</arg>
         <arg choice="req"><replaceable>node</replaceable></arg>
       </cmdsynopsis>
 
@@ -610,10 +611,15 @@
       </para>
 
       <para>
-        In case a node is demoted from the master candidate role, but
-        there are not enough new nodes for this case, the operation
-        will be refused. To override this check, pass the
-        <option>--force</option> option.
+        In case a node is demoted from the master candidate role, the
+        operation will be refused unless you pass
+        the <option>--auto-promote</option> option. This option will
+        cause the operation to lock all cluster nodes (thus it will
+        not be able to run in parallel with most other jobs), but it
+        allows automated maintenance of the cluster candidate pool. If
+        locking all cluster node is too expensive, another option is
+        to promote manually another node to master candidate before
+        demoting the current one.
       </para>
 
       <para>
diff --git a/scripts/gnt-node b/scripts/gnt-node
index aaef9daa3..5c985619e 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -635,7 +635,8 @@ def SetNodeParams(opts, args):
                                master_candidate=candidate,
                                offline=offline,
                                drained=drained,
-                               force=opts.force)
+                               force=opts.force,
+                               auto_promote=opts.auto_promote)
 
   # even if here we process the result, we allow submit only
   result = SubmitOrSend(op, opts)
@@ -681,7 +682,8 @@ commands = {
     (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
   'modify': (
     SetNodeParams, ARGS_ONE_NODE,
-    [FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT],
+    [FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT,
+     AUTO_PROMOTE_OPT],
     "<node_name>", "Alters the parameters of a node"),
   'powercycle': (
     PowercycleNode, ARGS_ONE_NODE,
-- 
GitLab