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)
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):
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])