From 0e4b36f4c550baf151a1bbc68e4ed1bea8cd3c94 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 22 Aug 2021 19:23:25 +0200 Subject: container: op-mode: T3765: move "connect container" command to container.xml.in file --- op-mode-definitions/containers.xml.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index a22549dd9..4c95fa315 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -17,6 +17,19 @@ + + + + + Attach to a running container + + container name + + + echo "Use Ctrl+p and Ctrl+q to detach"; sudo podman attach "$3" + + + -- cgit v1.2.3 From deaa1e8b65bdaf89caa9855d659dd7da459cf415 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 22 Aug 2021 19:23:34 +0200 Subject: container: op-mode: T3765: add "restart container" command --- op-mode-definitions/containers.xml.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index 4c95fa315..94dd24369 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -71,4 +71,17 @@ + + + + + Restart a given container + + container name + + + sudo podman restart "$3" + + + -- cgit v1.2.3 From a1873a39f4fb9e8445b772b3fc1697f55314888a Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 22 Aug 2021 20:35:46 +0200 Subject: container: op-mode: T3765: add "show log container" command --- op-mode-definitions/containers.xml.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index 94dd24369..8cc30d3a8 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -69,6 +69,19 @@ + + + + + Show logs from a given container + + container name + + + sudo podman logs --names "$4" + + + -- cgit v1.2.3 From 1b0d7b9e027672a95535d18e550919aff7e41ee3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 22 Aug 2021 20:51:34 +0200 Subject: log --- op-mode-definitions/containers.xml.in | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index 8cc30d3a8..1ed569407 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -61,6 +61,15 @@ sudo ${vyos_op_scripts_dir}/containers_op.py --image + + + Show logs from a given container + + container name + + + sudo podman logs --names "$4" + Show available container networks -- cgit v1.2.3 From 461e3e1b47813d808bf22c9f8e2d8d8fb427fac2 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 23 Aug 2021 11:46:20 +0200 Subject: container: T2216: add completion helper for "delete container image" --- op-mode-definitions/containers.xml.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index 1ed569407..e93487105 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -40,6 +40,9 @@ Delete container image + + + sudo ${vyos_op_scripts_dir}/containers_op.py --remove "${4}" -- cgit v1.2.3 From a1f82a06e1a1788164f52ef291a1275568912b9b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 23 Aug 2021 14:42:54 +0200 Subject: container: T2216: op-mode now supports updating the image for a given container --- op-mode-definitions/containers.xml.in | 20 ++++++++++++++ src/op_mode/containers_op.py | 49 ++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 15 deletions(-) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index e93487105..efa72e1a4 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -109,4 +109,24 @@ + + + + + Update a container image + + + + + Delete container image + + container name + + + sudo ${vyos_op_scripts_dir}/containers_op.py --update "${4}" + + + + + diff --git a/src/op_mode/containers_op.py b/src/op_mode/containers_op.py index 1e3fc3a8f..bc317029c 100755 --- a/src/op_mode/containers_op.py +++ b/src/op_mode/containers_op.py @@ -15,10 +15,10 @@ # along with this program. If not, see . import argparse -from vyos.configquery import query_context, ConfigQueryError -from vyos.util import cmd -config, op = query_context() +from getpass import getuser +from vyos.configquery import ConfigTreeQuery +from vyos.util import cmd parser = argparse.ArgumentParser() parser.add_argument("-a", "--all", action="store_true", help="Show all containers") @@ -26,34 +26,53 @@ parser.add_argument("-i", "--image", action="store_true", help="Show container i parser.add_argument("-n", "--networks", action="store_true", help="Show container images") parser.add_argument("-p", "--pull", action="store", help="Pull image for container") parser.add_argument("-d", "--remove", action="store", help="Delete container image") +parser.add_argument("-u", "--update", action="store", help="Update given container image") -if not config.exists(['container']): +config = ConfigTreeQuery() +base = ['container'] +if not config.exists(base): print('Containers not configured') exit(0) +if getuser() != 'root': + raise OSError('This functions needs to be run as root to return correct results!') + if __name__ == '__main__': args = parser.parse_args() if args.all: print(cmd('podman ps --all')) - exit(0) - if args.image: + + elif args.image: print(cmd('podman image ls')) - exit(0) - if args.networks: + + elif args.networks: print(cmd('podman network ls')) - exit(0) - if args.pull: + + elif args.pull: image = args.pull try: - print(cmd(f'sudo podman image pull {image}')) + print(cmd(f'podman image pull {image}')) except: print(f'Can\'t find or download image "{image}"') - exit(0) - if args.remove: + + elif args.remove: image = args.remove try: - print(cmd(f'sudo podman image rm {image}')) + print(cmd(f'podman image rm {image}')) except: print(f'Can\'t delete image "{image}"') - exit(0) + + elif args.update: + tmp = config.get_config_dict(base + ['name', args.update], + key_mangling=('-', '_'), get_first_key=True) + try: + image = tmp['image'] + print(cmd(f'podman image pull {image}')) + except: + print(f'Can\'t find or download image "{image}"') + else: + parser.print_help() + exit(1) + + exit(0) -- cgit v1.2.3 From f3ff81f4f31cd3ecb5d648caff674663943db42f Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 23 Aug 2021 21:04:59 +0200 Subject: container: op-mode: T3765: "connect container" will now drop you to a shell Commit a30d74f4 (container: op-mode: T3765: add "connect container mysql-server") added a CLI op-mode command to attach to a container - users typically not want to attach and consume stdout (can be done via logs) but rather wan't to debug inside the container image. vyos@vyos:~$ connect container unifi USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 202 0.0 0.0 4640 828 pts/1 Ss 21:06 0:00 /bin/sh root 203 0.0 0.0 34416 2872 pts/1 R+ 21:06 0:00 \_ ps faux root 187 0.0 0.0 18388 3124 ? S 21:03 0:00 /bin/bash root 186 0.0 0.0 4640 788 ? S 21:03 0:00 /bin/sh root 185 0.0 0.0 4640 824 ? S 21:03 0:00 /bin/sh root 184 0.0 0.0 4640 836 ? S 21:03 0:00 /bin/sh root 1 0.0 0.0 18520 3228 pts/0 Ss+ 20:50 0:00 bash /usr/local/bin/docker-entrypoint.sh unifi root 12 4.8 14.2 3688080 572756 pts/0 Sl+ 20:50 0:48 java -Dunifi.datadir=/unifi/data -Dunifi.logdir=/unifi/log -Dunifi.rundir=/var/run/unifi - root 35 0.7 3.4 1102700 139752 pts/0 Sl+ 20:50 0:07 \_ bin/mongod --dbpath /usr/lib/unifi/data/db --port 27117 --unixSocketPrefix /usr/lib/un Linux 57c689f739ed 5.10.60-amd64-vyos #1 SMP Fri Aug 20 14:44:59 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux --- op-mode-definitions/containers.xml.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'op-mode-definitions/containers.xml.in') diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in index efa72e1a4..b2b318786 100644 --- a/op-mode-definitions/containers.xml.in +++ b/op-mode-definitions/containers.xml.in @@ -26,7 +26,7 @@ container name - echo "Use Ctrl+p and Ctrl+q to detach"; sudo podman attach "$3" + sudo podman exec --interactive --tty "$3" /bin/sh -- cgit v1.2.3