From 5f83e263372778265ade51e7d385a00ebb87758b Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 31 Mar 2008 14:39:50 +0000
Subject: [PATCH] Change the 'gnt-cluster command' execution order

This patch makes the command execute last on the master (if the master
is selected). The order for the other nodes is unchanged.

The patch also updates the man page with some explanations and an
example.

Reviewed-by: imsnah
---
 lib/cmdlib.py        |  8 +++++++-
 man/gnt-cluster.sgml | 15 +++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 13138a543..38c36c855 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1039,7 +1039,7 @@ class LUSetClusterParams(LogicalUnit):
     """Check prerequisites.
 
     This checks whether the given params don't conflict and
-    if the given volume group is valid. 
+    if the given volume group is valid.
 
     """
     if not self.op.vg_name:
@@ -1832,6 +1832,12 @@ class LURunClusterCommand(NoHooksLU):
     """Run a command on some nodes.
 
     """
+    # put the master at the end of the nodes list
+    master_node = self.sstore.GetMasterNode()
+    if master_node in self.nodes:
+      self.nodes.remove(master_node)
+      self.nodes.append(master_node)
+
     data = []
     for node in self.nodes:
       result = self.ssh.Run(node, "root", self.op.command)
diff --git a/man/gnt-cluster.sgml b/man/gnt-cluster.sgml
index 4c5544997..947237570 100644
--- a/man/gnt-cluster.sgml
+++ b/man/gnt-cluster.sgml
@@ -101,6 +101,21 @@
 
       </para>
 
+      <para>
+        The command is executed serially on the selected nodes. If the
+        master node is present in the list, the command will be
+        executed last on the master. Regarding the other nodes, the
+        execution order is somewhat alphabetic (it's smarter so that
+        node2.example.com will be earlier than node10.example.com but
+        after node1.example.com).
+      </para>
+
+      <para>
+        So given the node names node1, node2, node3, node10, node11,
+        with node3 being the master, the order will be: node1, node2,
+        node10, node11, node3.
+      </para>
+
       <para>
         The command is constructed by concatenating all other command
         line arguments. For example, to list the contents of the
-- 
GitLab