summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-02-24 10:27:26 +0100
committerGitHub <noreply@github.com>2024-02-24 10:27:26 +0100
commit52df4d62074a76eb173931c5fbaf5a4e22d6e346 (patch)
tree3f4dd10dbc5e01082865fdbb3248b89f97271b44
parentc725b2d86c71c9a390d4ed376df58c549985e396 (diff)
parent9e51a1661fac3e0d762cffdd28705e7e4bad76e9 (diff)
downloadvyos-1x-52df4d62074a76eb173931c5fbaf5a4e22d6e346.tar.gz
vyos-1x-52df4d62074a76eb173931c5fbaf5a4e22d6e346.zip
Merge pull request #3046 from c-po/container-T6060
container: T6060: support removing all container images at once via op-mode
-rw-r--r--op-mode-definitions/container.xml.in1
-rwxr-xr-xsrc/op_mode/container.py12
2 files changed, 8 insertions, 5 deletions
diff --git a/op-mode-definitions/container.xml.in b/op-mode-definitions/container.xml.in
index 96c582a83..4aa13e913 100644
--- a/op-mode-definitions/container.xml.in
+++ b/op-mode-definitions/container.xml.in
@@ -41,6 +41,7 @@
<properties>
<help>Delete container image</help>
<completionHelp>
+ <list>all</list>
<script>sudo podman image ls -q</script>
</completionHelp>
</properties>
diff --git a/src/op_mode/container.py b/src/op_mode/container.py
index 385843b37..dcbb4dc55 100755
--- a/src/op_mode/container.py
+++ b/src/op_mode/container.py
@@ -31,7 +31,6 @@ def _get_json_data(command: str) -> list:
"""
return cmd(f'{command} --format json')
-
def _get_raw_data(command: str) -> list:
json_data = _get_json_data(command)
data = json.loads(json_data)
@@ -69,6 +68,13 @@ def add_image(name: str):
def delete_image(name: str):
from vyos.utils.process import rc_cmd
+ if name == 'all':
+ # gather list of all images and pass them to the removal list
+ name = cmd('sudo podman image ls --quiet')
+ # If there are no container images left, we can not delete them all
+ if not name: return
+ # replace newline with whitespace
+ name = name.replace('\n', ' ')
rc, output = rc_cmd(f'podman image rm --force {name}')
if rc != 0:
raise vyos.opmode.InternalError(output)
@@ -81,7 +87,6 @@ def show_container(raw: bool):
else:
return cmd(command)
-
def show_image(raw: bool):
command = 'podman image ls'
container_data = _get_raw_data('podman image ls')
@@ -90,7 +95,6 @@ def show_image(raw: bool):
else:
return cmd(command)
-
def show_network(raw: bool):
command = 'podman network ls'
container_data = _get_raw_data(command)
@@ -99,7 +103,6 @@ def show_network(raw: bool):
else:
return cmd(command)
-
def restart(name: str):
from vyos.utils.process import rc_cmd
@@ -110,7 +113,6 @@ def restart(name: str):
print(f'Container "{name}" restarted!')
return output
-
if __name__ == '__main__':
try:
res = vyos.opmode.run(sys.modules[__name__])