From da2eb513bad11517d7fbbc931f3b4fb411720c54 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Jun 2018 14:38:03 -0400 Subject: [PATCH] Better SSH interface --- libremanage.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libremanage.py b/libremanage.py index 44d10bb..c56f12c 100644 --- a/libremanage.py +++ b/libremanage.py @@ -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]) -- 2.25.1