From 177663688be751d691b116e291663df2a3e0e9ef Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 28 Jan 2023 20:19:04 +0100 Subject: host-control: Add unit-docker-shell action Signed-off-by: Paul Kocialkowski --- host-control | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3