summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-02-24 13:15:45 +0100
committerGitHub <noreply@github.com>2024-02-24 13:15:45 +0100
commit0be3d1f64bea6e3b52f58a1da056179f88baff9d (patch)
tree8a9f82c8f06425bae06777583fc00c31f6d8406c
parent8783db146fa5ed7528f9ed825cefc10100e4d194 (diff)
parent36957f8f48570ae2f457fd0a55804d7af5ac4b6a (diff)
downloadvyos-1x-0be3d1f64bea6e3b52f58a1da056179f88baff9d.tar.gz
vyos-1x-0be3d1f64bea6e3b52f58a1da056179f88baff9d.zip
Merge pull request #3048 from vyos/mergify/bp/sagitta/pr-3046
container: T6060: support removing all container images at once via op-mode (backport #3046)
-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__])