From 60c3f92af13faf2ab661ed353f49543958248589 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Jun 2018 16:54:03 -0400 Subject: [PATCH] FIx configuration, TTY setting, etc --- libremanage | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libremanage b/libremanage index 8d63eed..283d575 100755 --- a/libremanage +++ b/libremanage @@ -35,16 +35,23 @@ Valid commands are as follows: - shutdown, reboot, poweron: Power management - tty: Open TTY in GNU Screen - sanity, sanity-sh: SSH sanity tests, ignore + +Define a configuration file in ~/.libremanage.json. See the included +config.json for an example. Servers correspond to managed servers; managers +correspond to single-board computers connecting the servers. libremanage SSHs +into the manager to access the server through the side-channel. """ import sys import json import functools import subprocess +import os.path def open_ssh(server, command, force_tty=False): config = server["ssh"] - subprocess.run(["ssh", "-t" if force_tty else "", config["username"] + "@" + config["host"], "-p", str(config["port"]), command]) + args = ["ssh"] + (["-t"] if force_tty else []) + [config["username"] + "@" + config["host"], "-p", str(config["port"]), command] + subprocess.run(args) def die_with_usage(message): print(message) @@ -104,8 +111,11 @@ def issue_command(server_name, command): # Load configuration, get command, and go! -with open("config.json") as f: - CONFIG = json.load(f) +try: + with open(os.path.expanduser("~/.libremanage.json")) as f: + CONFIG = json.load(f) +except FileNotFoundError: + die_with_usage("Configuration file missing in ~/.libremanage.json") if len(sys.argv) != 3: die_with_usage("Incorrect number of arguments") -- 2.25.1