Better SSH interface
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 18:38:03 +0000 (14:38 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 18:38:03 +0000 (14:38 -0400)
libremanage.py

index 44d10bb2bd65e7bc20977455099b310fd81c4fe0..c56f12c9a5480513714db26a5ece5c380e575e2d 100644 (file)
@@ -42,8 +42,8 @@ Valid commands are as follows:
 with open("config.json") as f:
     CONFIG = json.load(f)
 
-def open_ssh(config):
-    subprocess.run(["ssh", config["username"] + "@" + config["host"], "-p", str(config["port"])])
+def open_ssh(config, command):
+    subprocess.run(["ssh", config["username"] + "@" + config["host"], "-p", str(config["port"]), command])
 
 def die_with_usage(message):
     print(message)
@@ -64,17 +64,18 @@ def set_server_power(state, server):
 COMMANDS = {
         # Power managemment
 
-        "shutdown": (False, functools.partial(set_server_power, 0)),
-        "poweron": (False, functools.partial(set_server_power, 1)),
-        "reboot": (False, lambda s: (set_server_power(0, s), set_server_power(1, s))),
+        "shutdown": functools.partial(set_server_power, 0),
+        "poweron": functools.partial(set_server_power, 1),
+        "reboot": lambda s: (set_server_power(0, s), set_server_power(1, s)),
 
         # TTY access (or keyboard if wired as such)
 
-        "tty": (True, lambda s: print("Screening on " + s)),
+        "tty": lambda s: print("Screening on " + s),
 
-        # SSH sanity test
+        # SSH sanity tests
 
-        "console": (True, lambda s: open_ssh(s["ssh"])),
+        "sanity": lambda s: open_ssh(s["ssh"], "whoami"),
+        "console": lambda s: open_ssh(s["ssh"], ""),
 }
 
 def issue_command(server_name, command):
@@ -82,11 +83,10 @@ def issue_command(server_name, command):
     print(server_name, command)
 
     try:
-        (visible_shell, callback) = COMMANDS[command]
+        callback = COMMANDS[command]
     except KeyError:
         die_with_usage("Invalid command supplied")
 
-    print("Shell visible? " + str(visible_shell))
     callback(server)
 
 issue_command(sys.argv[1], sys.argv[2])