Feed comamnds through via partial application
[libremanage.git] / libremanage.py
index 9bfacfceae9016cdfba93b6e415d7ead14ec2536..bab34b1974daf73547c4217b6a43b6cbac8b764a 100644 (file)
@@ -18,6 +18,7 @@ along with this program.  If not, see <https://www.gnu.org/licenses/>.
 """
 
 import sys
+import functools
 
 USAGE = """
 Usage:
@@ -40,7 +41,21 @@ if len(sys.argv) != 3:
     print(USAGE)
     sys.exit(1)
 
+def get_server_handle(name):
+    # TODO: resolve based on config, SSH in, give self-contained handle?
+    return name
+
+def set_server_power(state, server):
+    print("Setting server " + server + " to power state " + str(state))
+
+COMMANDS = {
+        "shutdown": functools.partial(set_server_power, 0),
+        "poweron": functools.partial(set_server_power, 1),
+}
+
 def issue_command(server_name, command):
+    server = get_server_handle(server_name)
     print(server_name, command)
+    COMMANDS[command](server_name)
 
 issue_command(sys.argv[1], sys.argv[2])