From 961576b22bb26281036e489430003842afb50e13 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 20 Sep 2024 11:42:48 -0400 Subject: [PATCH] add ramalama stop --ignore option Signed-off-by: Daniel J Walsh --- Makefile | 1 - docs/ramalama-stop.1.md | 3 +++ ramalama/cli.py | 16 +++++++--------- test/system/040-serve.bats | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 60337c51..58b86c66 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,6 @@ docs: .PHONY: lint lint: @pip install -q black flake8 - echo $$PATH black --line-length 120 --exclude 'venv/*' *.py ramalama/*.py # Format the code flake8 --max-line-length=120 --exclude=venv *.py ramalama/*.py # Check for any inconsistencies diff --git a/docs/ramalama-stop.1.md b/docs/ramalama-stop.1.md index b9f4a0b5..c6d0068e 100644 --- a/docs/ramalama-stop.1.md +++ b/docs/ramalama-stop.1.md @@ -14,6 +14,9 @@ Stop all containers #### **--help**, **-h** Print usage message +#### **--ignore** +Ignore missing containers when stopping + ## DESCRIPTION Stop specified container that is executing the AI Model. diff --git a/ramalama/cli.py b/ramalama/cli.py index 03c87edf..8c5d4455 100644 --- a/ramalama/cli.py +++ b/ramalama/cli.py @@ -348,37 +348,35 @@ def stop_parser(subparsers): parser = subparsers.add_parser("stop", help="Stop named container that is running AI Model") parser.add_argument("--nocontainer", default=True, action="store_true", help=argparse.SUPPRESS) parser.add_argument("-a", "--all", action="store_true", help="Stop all ramalama containers") + parser.add_argument( + "--ignore", action="store_true", help="Ignore errors when specified ramalama containersis missing" + ) parser.add_argument("NAME", nargs="?") # positional argument parser.set_defaults(func=stop_container) -def _stop_container(name): +def _stop_container(args, name): if not name: raise IndexError("must specify a container name") conman = container_manager() if conman == "": raise IndexError("no container manager (Podman, Docker) found") - conman_args = [ - conman, - "stop", - "-t=0", - name, - ] + conman_args = [conman, "stop", "-t=0", "--ignore=" + str(args.ignore), name] run_cmd(conman_args) def stop_container(args): if not args.all: - return _stop_container(args.NAME) + return _stop_container(args, args.NAME) if args.NAME: raise IndexError("specifying --all and container name, %s, not allowed" % args.NAME) args.noheading = True args.format = "{{ .Names }}" for i in _list_containers(args): - _stop_container(i) + _stop_container(args, i) def version_parser(subparsers): diff --git a/test/system/040-serve.bats b/test/system/040-serve.bats index e6e57418..ad2468a8 100644 --- a/test/system/040-serve.bats +++ b/test/system/040-serve.bats @@ -85,6 +85,9 @@ verify_begin="podman run --rm -it --label=RAMALAMA container --security-opt=labe run_ramalama 125 stop ${name} is "$output" "Error: no container with name or ID \"${name}\" found: no such container" "missing container" + run_ramalama stop --ignore ${name} + is "$output" "" "ignore missing" + run_ramalama 22 stop --all ${name} is "$output" "Error: specifying --all and container name, ${name}, not allowed" "list correct" }