Adding backend functionality to call oob helper
authorRené Nussbaumer <rn@google.com>
Wed, 1 Dec 2010 10:08:47 +0000 (11:08 +0100)
committerRené Nussbaumer <rn@google.com>
Wed, 1 Dec 2010 13:36:32 +0000 (14:36 +0100)
Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/backend.py
lib/constants.py

index 2cb5ba1..b6f7ceb 100644 (file)
@@ -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.
 
index cd6d4fe..ffb0dab 100644 (file)
@@ -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"