Add two new opcode options to LUOobCommand
authorRené Nussbaumer <rn@google.com>
Mon, 31 Jan 2011 12:54:42 +0000 (13:54 +0100)
committerRené Nussbaumer <rn@google.com>
Mon, 31 Jan 2011 17:06:32 +0000 (18:06 +0100)
This patch adds ignore_status to ignore the offline flag of nodes
and also adds a force_master option to force operations on master node
if they will make the master unavailable (for some time).

Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/cmdlib.py
lib/opcodes.py

index 214e2bb..caf6cd9 100644 (file)
@@ -3227,6 +3227,7 @@ class LUOobCommand(NoHooksLU):
 
     """
     self.nodes = []
+    master_node = self.cfg.GetMasterNode()
     for node_name in self.op.node_names:
       node = self.cfg.GetNodeInfo(node_name)
 
@@ -3236,11 +3237,33 @@ class LUOobCommand(NoHooksLU):
       else:
         self.nodes.append(node)
 
-      if (self.op.command == constants.OOB_POWER_OFF and not node.offline):
+      if (not self.op.ignore_status and
+          (self.op.command == constants.OOB_POWER_OFF and not node.offline)):
         raise errors.OpPrereqError(("Cannot power off node %s because it is"
                                     " not marked offline") % node_name,
                                    errors.ECODE_STATE)
 
+    if self.op.command in (constants.OOB_POWER_OFF, constants.OOB_POWER_CYCLE):
+      # This does two things, it checks if master is in the list and if so and
+      # force_master is set it puts it to the end so the master is done last
+      try:
+        self.op.node_names.remove(master_node)
+      except ValueError:
+        pass
+      else:
+        if self.op.force_master:
+          self.op.node_names.append(master_node)
+        else:
+          self.LogWarning("Master %s was skipped, use the force master"
+                          " option to operate on the master too",
+                          master_node)
+          if not self.op.node_names:
+            raise errors.OpPrereqError("No nodes left to operate on, aborting",
+                                       errors.ECODE_INVAL)
+
+      assert (master_node not in self.op.node_names or
+              self.op.node_names[-1] == master_node)
+
   def ExpandNames(self):
     """Gather locks we need.
 
index 0293ba4..2b18f5e 100644 (file)
@@ -593,6 +593,8 @@ class OpOobCommand(OpCode):
     ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
     ("command", None, ht.TElemOf(constants.OOB_COMMANDS)),
     ("timeout", constants.OOB_TIMEOUT, ht.TInt),
+    ("ignore_status", False, ht.TBool),
+    ("force_master", False, ht.TBool),
     ]