Expose nicely
[libremanage.git] / libremanage
index 51bb8e26e9a9e466de764d9d993c89cc6ebe09ac..c47c4a6873960e43b86d2223eba778394de4715f 100755 (executable)
@@ -68,6 +68,9 @@ def get_server_handle(name):
     # Associate manager configuration
     server["ssh"] = CONFIG["managers"][server["manager"]]
 
+    # Meta access
+    server["name"] = name
+
     return server
 
 def gpio_export(server, pin, mode):
@@ -112,6 +115,14 @@ def set_server_power(state, server):
 
     gpio_export(server, pin, False)
 
+def open_tty(s):
+    if s["tty"]["uncolor"]:
+        # Broken serial port, workaround TTY garbage with libremanage-serial
+        subprocess.run(["libremanage-serial", s["name"])
+    else:
+        # Use native GNU screen
+        return open_ssh(s, "screen " + s["tty"]["file"] + " " + str(s["tty"]["baud"]), force_tty=True),
+
 COMMANDS = {
         # Power managemment
 
@@ -121,7 +132,7 @@ COMMANDS = {
 
         # TTY access (or keyboard if wired as such)
 
-        "tty": lambda s: open_ssh(s, "screen " + s["tty"]["file"] + " " + str(s["tty"]["baud"]), force_tty=True),
+        "tty": open_tty, 
         "tty-baud": lambda s: open_ssh(s, "stty -F "+ s["tty"]["file"] + " " + str(s["tty"]["baud"])),
         "tty-read": lambda s: open_ssh(s, "cat " + s["tty"]["file"], force_tty=True),
         "tty-write": lambda s: open_ssh(s, "stdbuf -o0 cat > " + s["tty"]["file"], force_tty=True),