From 7e7c6a5f120f317e3e4555939a099f48cf0b27e0 Mon Sep 17 00:00:00 2001 From: Christian Poessinger <christian@poessinger.com> Date: Sun, 8 May 2022 21:52:51 +0200 Subject: container: op-mode: T3852: use XML inline podman commands Reduce bloat of containers_op.py wrapper script. All commands can be passed directly to podman via the XML script. This also makes the execution faster, as no Python environment needs to be build up. --- op-mode-definitions/container.xml.in | 176 ++++++++++++++++++++++++++++++++++ op-mode-definitions/containers.xml.in | 176 ---------------------------------- 2 files changed, 176 insertions(+), 176 deletions(-) create mode 100644 op-mode-definitions/container.xml.in delete mode 100644 op-mode-definitions/containers.xml.in (limited to 'op-mode-definitions') diff --git a/op-mode-definitions/container.xml.in b/op-mode-definitions/container.xml.in new file mode 100644 index 000000000..fa66402dc --- /dev/null +++ b/op-mode-definitions/container.xml.in @@ -0,0 +1,176 @@ +<?xml version="1.0"?> +<interfaceDefinition> + <node name="add"> + <children> + <node name="container"> + <properties> + <help>Add container image</help> + </properties> + <children> + <tagNode name="image"> + <properties> + <help>Pull a new image for container</help> + </properties> + <command>sudo podman image pull "${4}"</command> + </tagNode> + </children> + </node> + </children> + </node> + <node name="connect"> + <children> + <tagNode name="container"> + <properties> + <help>Attach to a running container</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>sudo podman exec --interactive --tty "$3" /bin/sh</command> + </tagNode> + </children> + </node> + <node name="delete"> + <children> + <node name="container"> + <properties> + <help>Delete container image</help> + </properties> + <children> + <tagNode name="image"> + <properties> + <help>Delete container image</help> + <completionHelp> + <script>sudo podman image ls -q</script> + </completionHelp> + </properties> + <command>sudo podman image rm --force "${4}"</command> + </tagNode> + </children> + </node> + </children> + </node> + <node name="generate"> + <children> + <node name="container"> + <properties> + <help>Generate Container Image</help> + </properties> + <children> + <tagNode name="image"> + <properties> + <help>Name of container image (tag)</help> + </properties> + <children> + <tagNode name="path"> + <properties> + <help>Path to Dockerfile</help> + <completionHelp> + <list><filename></list> + </completionHelp> + </properties> + <command>sudo podman build --layers --force-rm --tag "$4" $6</command> + </tagNode> + </children> + </tagNode> + </children> + </node> + </children> + </node> + <node name="monitor"> + <children> + <node name="log"> + <children> + <tagNode name="container"> + <properties> + <help>Monitor last lines of container logs</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>sudo podman logs --follow --names "$4"</command> + </tagNode> + </children> + </node> + </children> + </node> + <node name="show"> + <children> + <node name="container"> + <properties> + <help>Show containers</help> + </properties> + <command>sudo podman ps --all</command> + <children> + <leafNode name="image"> + <properties> + <help>Show container image</help> + </properties> + <command>sudo podman image ls</command> + </leafNode> + <tagNode name="log"> + <properties> + <help>Show logs from a given container</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>sudo podman logs --names "$4"</command> + </tagNode> + <leafNode name="network"> + <properties> + <help>Show available container networks</help> + </properties> + <command>sudo podman network ls</command> + </leafNode> + </children> + </node> + <node name="log"> + <children> + <tagNode name="container"> + <properties> + <help>Show logs from a given container</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>sudo podman logs --names "$4"</command> + </tagNode> + </children> + </node> + </children> + </node> + <node name="restart"> + <children> + <tagNode name="container"> + <properties> + <help>Restart a given container</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>sudo podman restart "$3"</command> + </tagNode> + </children> + </node> + <node name="update"> + <children> + <node name="container"> + <properties> + <help>Update a container image</help> + </properties> + <children> + <tagNode name="image"> + <properties> + <help>Update container image</help> + <completionHelp> + <path>container name</path> + </completionHelp> + </properties> + <command>if cli-shell-api existsActive container name "$4"; then sudo podman pull $(cli-shell-api returnActiveValue container name "$4" image); else echo "Container $4 does not exist"; fi</command> + </tagNode> + </children> + </node> + </children> + </node> +</interfaceDefinition> diff --git a/op-mode-definitions/containers.xml.in b/op-mode-definitions/containers.xml.in deleted file mode 100644 index 48501bd84..000000000 --- a/op-mode-definitions/containers.xml.in +++ /dev/null @@ -1,176 +0,0 @@ -<?xml version="1.0"?> -<interfaceDefinition> - <node name="add"> - <children> - <node name="container"> - <properties> - <help>Add container image</help> - </properties> - <children> - <tagNode name="image"> - <properties> - <help>Pull a new image for container</help> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --pull "${4}"</command> - </tagNode> - </children> - </node> - </children> - </node> - <node name="connect"> - <children> - <tagNode name="container"> - <properties> - <help>Attach to a running container</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo podman exec --interactive --tty "$3" /bin/sh</command> - </tagNode> - </children> - </node> - <node name="delete"> - <children> - <node name="container"> - <properties> - <help>Delete container image</help> - </properties> - <children> - <tagNode name="image"> - <properties> - <help>Delete container image</help> - <completionHelp> - <script>sudo podman image ls -q</script> - </completionHelp> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --remove "${4}"</command> - </tagNode> - </children> - </node> - </children> - </node> - <node name="generate"> - <children> - <node name="container"> - <properties> - <help>Generate Container Image</help> - </properties> - <children> - <tagNode name="image"> - <properties> - <help>Name of container image (tag)</help> - </properties> - <children> - <tagNode name="path"> - <properties> - <help>Path to Dockerfile</help> - <completionHelp> - <list><filename></list> - </completionHelp> - </properties> - <command>sudo podman build --layers --force-rm --tag "$4" $6</command> - </tagNode> - </children> - </tagNode> - </children> - </node> - </children> - </node> - <node name="monitor"> - <children> - <node name="log"> - <children> - <tagNode name="container"> - <properties> - <help>Monitor last lines of container logs</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo podman logs --follow --names "$4"</command> - </tagNode> - </children> - </node> - </children> - </node> - <node name="show"> - <children> - <node name="container"> - <properties> - <help>Show containers</help> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --all</command> - <children> - <leafNode name="image"> - <properties> - <help>Show container image</help> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --image</command> - </leafNode> - <tagNode name="log"> - <properties> - <help>Show logs from a given container</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo podman logs --names "$4"</command> - </tagNode> - <leafNode name="network"> - <properties> - <help>Show available container networks</help> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --networks</command> - </leafNode> - </children> - </node> - <node name="log"> - <children> - <tagNode name="container"> - <properties> - <help>Show logs from a given container</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo podman logs --names "$4"</command> - </tagNode> - </children> - </node> - </children> - </node> - <node name="restart"> - <children> - <tagNode name="container"> - <properties> - <help>Restart a given container</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo podman restart "$3"</command> - </tagNode> - </children> - </node> - <node name="update"> - <children> - <node name="container"> - <properties> - <help>Update a container image</help> - </properties> - <children> - <tagNode name="image"> - <properties> - <help>Update container image</help> - <completionHelp> - <path>container name</path> - </completionHelp> - </properties> - <command>sudo ${vyos_op_scripts_dir}/containers_op.py --update "${4}"</command> - </tagNode> - </children> - </node> - </children> - </node> -</interfaceDefinition> -- cgit v1.2.3