2 libremanage - Lightweight, free software for remote side-chanel server management
4 Copyright (C) 2018 Alyssa Rosenzweig
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
28 $ libremanage [server name] [command]
32 $ libremanage web2 reboot
34 Server names are defined in the accompanying config.py.
36 Valid commands are as follows:
38 - shutdown, reboot, poweron: Power management
39 - tty: Open TTY in GNU Screen
42 with
open("config.json") as f
:
46 subprocess
.run(["ssh", config
["username"] + "@" + config
["host"], "-p", str(config
["port"])])
48 open_ssh(CONFIG
["managers"]["myboard"])
51 def die_with_usage(message
):
56 if len(sys
.argv
) != 3:
57 die_with_usage("Incorrect number of arguments")
59 def get_server_handle(name
):
60 # TODO: resolve based on config, SSH in, give self-contained handle?
63 def set_server_power(state
, server
):
64 print("Setting server " + server
+ " to power state " + str(state
))
69 "shutdown": (False, functools
.partial(set_server_power
, 0)),
70 "poweron": (False, functools
.partial(set_server_power
, 1)),
71 "reboot": (False, lambda s
: (set_server_power(0, s
), set_server_power(1, s
))),
73 # TTY access (or keyboard if wired as such)
75 "tty": (True, lambda s
: print("Screening on " + s
)),
78 "sanity": (True, lambda s
: print("Sanity"))
81 def issue_command(server_name
, command
):
82 server
= get_server_handle(server_name
)
83 print(server_name
, command
)
86 (visible_shell
, callback
) = COMMANDS
[command
]
88 die_with_usage("Invalid command supplied")
90 print("Shell visible? " + str(visible_shell
))
93 issue_command(sys
.argv
[1], sys
.argv
[2])