From beff3779e1e44c2d771e88f1c40db75c8547ac12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Tue, 8 Mar 2011 11:56:57 +0100
Subject: [PATCH] OpOobCommand: Adding power on delay
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This delays the invocation of the power on of the next node. So if you
power on a bunch of nodes it will not blow the fuse.

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cmdlib.py    | 8 +++++++-
 lib/constants.py | 1 +
 lib/ht.py        | 4 ++++
 lib/opcodes.py   | 2 ++
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 3841689d7..051e5feaf 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -3249,6 +3249,8 @@ class LUOobCommand(NoHooksLU):
     self.nodes = []
     self.master_node = self.cfg.GetMasterNode()
 
+    assert self.op.power_delay >= 0.0
+
     if self.op.node_names:
       if self.op.command in self._SKIP_MASTER:
         if self.master_node in self.op.node_names:
@@ -3312,7 +3314,7 @@ class LUOobCommand(NoHooksLU):
     master_node = self.master_node
     ret = []
 
-    for node in self.nodes:
+    for idx, node in enumerate(self.nodes):
       node_entry = [(constants.RS_NORMAL, node.name)]
       ret.append(node_entry)
 
@@ -3366,6 +3368,10 @@ class LUOobCommand(NoHooksLU):
 
           node_entry.append((constants.RS_NORMAL, result.payload))
 
+          if (self.op.command == constants.OOB_POWER_ON and
+              idx < len(self.nodes) - 1):
+            time.sleep(self.op.power_delay)
+
     return ret
 
   def _CheckPayload(self, result):
diff --git a/lib/constants.py b/lib/constants.py
index 154b2947c..44550e5a5 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -702,6 +702,7 @@ OOB_COMMANDS = frozenset([OOB_POWER_ON, OOB_POWER_OFF, OOB_POWER_CYCLE,
 OOB_POWER_STATUS_POWERED = "powered"
 
 OOB_TIMEOUT = 60 # 60 seconds
+OOB_POWER_DELAY = 2.0 # 2 seconds
 
 OOB_STATUS_OK = "OK"
 OOB_STATUS_WARNING = "WARNING"
diff --git a/lib/ht.py b/lib/ht.py
index ffc6b4427..f2fc0b388 100644
--- a/lib/ht.py
+++ b/lib/ht.py
@@ -267,6 +267,10 @@ TPositiveInt = \
 TStrictPositiveInt = \
   TAnd(TInt, WithDesc("GreaterThanZero")(lambda v: v > 0))
 
+#: a positive float
+TPositiveFloat = \
+  TAnd(TFloat, WithDesc("EqualGreaterZero")(lambda v: v >= 0.0))
+
 
 def TListOf(my_type):
   """Checks if a given value is a list with all elements of the same type.
diff --git a/lib/opcodes.py b/lib/opcodes.py
index e36e2566b..9a3a53484 100644
--- a/lib/opcodes.py
+++ b/lib/opcodes.py
@@ -678,6 +678,8 @@ class OpOobCommand(OpCode):
      "Timeout before the OOB helper will be terminated"),
     ("ignore_status", False, ht.TBool,
      "Ignores the node offline status for power off"),
+    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
+     "Time in seconds to wait between powering on nodes"),
     ]
 
 
-- 
GitLab