Refactor for real SSH
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 18:33:36 +0000 (14:33 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 25 Jun 2018 18:33:36 +0000 (14:33 -0400)
config.json
libremanage.py

index fcdccb23b1c231391b27f510048684939bece525..5594855812035673c914791050c06143439970b6 100644 (file)
@@ -1,7 +1,9 @@
 {
        "servers": {
                "web2": {
-                       "manager": "myboard"
+                       "manager": "myboard",
+                       "tty": "/dev/ttyUSB0",
+                       "baud": 115200
                }
        },
        "managers": {
index 37e1b59b1aa3af1240f6f00e3dc074d816e6c44d..44d10bb2bd65e7bc20977455099b310fd81c4fe0 100644 (file)
@@ -45,9 +45,6 @@ with open("config.json") as f:
 def open_ssh(config):
     subprocess.run(["ssh", config["username"] + "@" + config["host"], "-p", str(config["port"])])
 
-open_ssh(CONFIG["managers"]["myboard"])
-print(CONFIG)
-
 def die_with_usage(message):
     print(message)
     print(USAGE)
@@ -57,8 +54,9 @@ if len(sys.argv) != 3:
     die_with_usage("Incorrect number of arguments")
 
 def get_server_handle(name):
-    # TODO: resolve based on config, SSH in, give self-contained handle?
-    return name
+    server = CONFIG["servers"][name]
+    server["ssh"] = CONFIG["managers"][server["manager"]]
+    return server
 
 def set_server_power(state, server):
     print("Setting server " + server + " to power state " + str(state))
@@ -75,7 +73,8 @@ COMMANDS = {
         "tty": (True, lambda s: print("Screening on " + s)),
 
         # SSH sanity test
-        "console": (True, lambda s: open_ssh(CONFIG["managers"]["myboard"])),
+
+        "console": (True, lambda s: open_ssh(s["ssh"])),
 }
 
 def issue_command(server_name, command):
@@ -88,6 +87,6 @@ def issue_command(server_name, command):
         die_with_usage("Invalid command supplied")
 
     print("Shell visible? " + str(visible_shell))
-    callback(server_name)
+    callback(server)
 
 issue_command(sys.argv[1], sys.argv[2])