diff options
author | Christian Breunig <christian@breunig.cc> | 2024-02-24 10:27:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-24 10:27:26 +0100 |
commit | 52df4d62074a76eb173931c5fbaf5a4e22d6e346 (patch) | |
tree | 3f4dd10dbc5e01082865fdbb3248b89f97271b44 /src/op_mode | |
parent | c725b2d86c71c9a390d4ed376df58c549985e396 (diff) | |
parent | 9e51a1661fac3e0d762cffdd28705e7e4bad76e9 (diff) | |
download | vyos-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
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/container.py | 12 |
1 files changed, 7 insertions, 5 deletions
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__]) |