From b2f29800416b515c43c5f69e4610f70342d44a50 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com>
Date: Wed, 1 Dec 2010 11:08:47 +0100
Subject: [PATCH] Adding backend functionality to call oob helper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: RenΓ© Nussbaumer <rn@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/backend.py   | 21 +++++++++++++++++++++
 lib/constants.py | 10 ++++++++++
 2 files changed, 31 insertions(+)

diff --git a/lib/backend.py b/lib/backend.py
index 2cb5ba1b7..b6f7ceb09 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1755,6 +1755,27 @@ def UploadFile(file_name, data, mode, uid, gid, atime, mtime):
                       atime=atime, mtime=mtime)
 
 
+def RunOob(oob_program, command, node, timeout):
+  """Executes oob_program with given command on given node.
+
+  @param oob_program: The path to the executable oob_program
+  @param command: The command to invoke on oob_program
+  @param node: The node given as an argument to the program
+  @param timeout: Timeout after which we kill the oob program
+
+  @return: stdout
+  @raise RPCFail: If execution fails for some reason
+
+  """
+  result = utils.RunCmd([oob_program, command, node], timeout=timeout)
+
+  if result.failed:
+    _Fail("'%s' failed with reason '%s'; output: %s", result.cmd,
+          result.fail_reason, result.output)
+
+  return result.stdout
+
+
 def WriteSsconfFiles(values):
   """Update all ssconf files.
 
diff --git a/lib/constants.py b/lib/constants.py
index cd6d4fe4b..ffb0dabff 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -645,6 +645,16 @@ NDS_PARAMETER_TYPES = {
 
 NDS_PARAMETERS = frozenset(NDS_PARAMETER_TYPES.keys())
 
+# OOB supported commands
+OOB_POWER_ON = "power-on"
+OOB_POWER_OFF = "power-off"
+OOB_POWER_CYCLE = "power-cycle"
+OOB_POWER_STATUS = "power-status"
+OOB_HEALTH = "health"
+
+OOB_COMMANDS = frozenset([OOB_POWER_ON, OOB_POWER_OFF, OOB_POWER_CYCLE,
+                          OOB_POWER_STATUS, OOB_HEALTH])
+
 # Instance Parameters Profile
 PP_DEFAULT = "default"
 
-- 
GitLab