diff options
author | Paul Kocialkowski | 2023-01-28 20:19:04 +0100 |
---|---|---|
committer | Paul Kocialkowski | 2023-01-28 21:35:17 +0100 |
commit | 177663688be751d691b116e291663df2a3e0e9ef (patch) | |
tree | 4f3686b952ad115478e9e2ed0ae655166b41af62 | |
parent | ed7e44f1396362d6d8dc2a11419fe3dc58bd5d5f (diff) |
host-control: Add unit-docker-shell action
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rwxr-xr-x | host-control | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/host-control b/host-control index 1b60b2f..efeea96 100755 --- a/host-control +++ b/host-control @@ -39,7 +39,8 @@ class host_control(): " unit-stop [unit] stop unit\n" \ " unit-restart [unit] restart unit\n" \ " unit-log [unit] show unit log\n" \ - " unit-update [unit] update unit" + " unit-update [unit] update unit\n" \ + " unit-docker-shell [unit] access unit docker shell" # trace @@ -214,6 +215,12 @@ class host_control(): return None + def unit_docker_container(self, unit): + if "docker-container" in unit: + return unit["docker-container"] + else: + return unit["name"] + def unit_systemctl(self, host, name, option): address = self.ssh_address(host) @@ -299,6 +306,19 @@ class host_control(): return 0 + def unit_docker_shell(self, host, name): + unit = self.unit_lookup(host, name) + if unit is None: + self.print_message("No " + name + " unit in host: " + self.host) + return 1 + + container = self.unit_docker_container(unit) + address = self.ssh_address(host) + command = self.ssh_command(address, [ "-t", "docker", "exec", "-ti", container, "sh" ]) + + self.print_command(command) + subprocess.call(command) + def unit_list(self, host): if not "units" in host: self.print_message("No units in host: " + self.host) @@ -486,6 +506,8 @@ class host_control(): return self.unit_log(host, arguments[1]) elif action == "unit-update": return self.unit_update(host, arguments[1]) + elif action == "unit-docker-shell": + return self.unit_docker_shell(host, arguments[1]) else: self.print_message("Unknown action: " + action) return 1 |