Skip to content

Commit

Permalink
Merge pull request #161 from rhatdan/stop
Browse files Browse the repository at this point in the history
add ramalama stop --ignore option
  • Loading branch information
ericcurtin authored Sep 20, 2024
2 parents 1cce996 + 961576b commit c57c9e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions docs/ramalama-stop.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 7 additions & 9 deletions ramalama/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions test/system/040-serve.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit c57c9e3

Please sign in to comment.