New poweroffs.py, powerons.py and gen_robot_plug_in.py.

Change-Id: I237dd5aab7a29466c6ec69451df9318415ea765f
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/boot/poweroffs.py b/lib/boot/poweroffs.py
new file mode 100755
index 0000000..55bb9bf
--- /dev/null
+++ b/lib/boot/poweroffs.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+
+r"""
+This module is the python counterpart to poweroffs.robot.  It provides
+functions for powering off an open bmc machine.
+"""
+
+import gen_robot_print as grp
+import state as state_mod
+
+from robot.libraries.BuiltIn import BuiltIn
+
+# We need utils.robot to get keyword "Initiate Power Off".
+BuiltIn().import_resource("utils.robot")
+
+
+###############################################################################
+def bmc_power_off():
+
+    r"""
+    Power the Open BMC machine off and monitor status to verify.
+    """
+
+    grp.rprint_timen("Refreshing state data.")
+    state = state_mod.get_state()
+    grp.rprint_var(state)
+
+    match_state = state_mod.anchor_state(state)
+
+    grp.rprintn()
+    cmd_buf = ["Initiate Power Off"]
+    grp.rpissuing_keyword(cmd_buf)
+    power = BuiltIn().run_keyword(*cmd_buf)
+
+    # Wait for the state to change in any way.
+    state_mod.wait_state(match_state, wait_time="1 min", interval="3 seconds",
+                         invert=1)
+
+    cmd_buf = ["Create Dictionary", "power=${0}",
+               "bmc=HOST_POWERED_OFF", "boot_progress=Off"]
+    grp.rdpissuing_keyword(cmd_buf)
+    final_state = BuiltIn().run_keyword(*cmd_buf)
+
+    final_state = state_mod.anchor_state(final_state)
+
+    grp.rprintn()
+    state_mod.wait_state(final_state, wait_time="2 min", interval="3 seconds")
+
+###############################################################################
diff --git a/lib/boot/powerons.py b/lib/boot/powerons.py
new file mode 100755
index 0000000..872912a
--- /dev/null
+++ b/lib/boot/powerons.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+r"""
+This module is the python counterpart to utils.robot.  It provides many
+functions for communicating with the Open BMC machine.
+"""
+
+import gen_robot_print as grp
+import state as state_mod
+
+from robot.libraries.BuiltIn import BuiltIn
+
+# We need utils.robot to get keyword "Initiate Power On".
+BuiltIn().import_resource("utils.robot")
+
+
+###############################################################################
+def bmc_power_on():
+
+    r"""
+    Power the Open BMC machine on and monitor status to verify.
+    """
+
+    grp.rprint_timen("Refreshing state data.")
+    state = state_mod.get_state()
+    grp.rprint_var(state)
+
+    match_state = state_mod.anchor_state(state)
+
+    grp.rprintn()
+    cmd_buf = ["Initiate Power On", "wait=${0}"]
+    grp.rpissuing_keyword(cmd_buf)
+    power = BuiltIn().run_keyword(*cmd_buf)
+
+    # Wait for the state to change in any way.
+    state_mod.wait_state(match_state, wait_time="1 min", interval="3 seconds",
+                         invert=1)
+
+    cmd_buf = ["Create Dictionary", "power=${1}",
+               "bmc=HOST_BOOTED",
+               "boot_progress=FW Progress, Starting OS"]
+    grp.rdpissuing_keyword(cmd_buf)
+    final_state = BuiltIn().run_keyword(*cmd_buf)
+
+    try:
+        os_host = BuiltIn().get_variable_value("${OS_HOST}")
+    except TypeError:
+        os_host = ""
+
+    if os_host != "":
+        final_state['os_ping'] = 1
+        final_state['os_login'] = 1
+        final_state['os_run_cmd'] = 1
+
+    final_state = state_mod.anchor_state(final_state)
+
+    grp.rprintn()
+    state_mod.wait_state(final_state, wait_time="7 min", interval="3 seconds")
+
+###############################################################################