From 00cef7f0fd7e7f5753873416be9b564f24fc71fd Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Wed, 16 Oct 2024 12:43:08 +0100 Subject: [PATCH] Check if podman machine is running before attempting to run We just get an ugly failure if podman machine isn't running and we attempt to use it. Signed-off-by: Eric Curtin --- ramalama/cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ramalama/cli.py b/ramalama/cli.py index a261763..9345da2 100644 --- a/ramalama/cli.py +++ b/ramalama/cli.py @@ -34,11 +34,17 @@ def ai_support_in_vm(conman): return False if conman == "podman": + podman_machine_list = ["podman", "machine", "list"] conman_args = [conman, "machine", "list", "--format", "{{ .VMType }}"] try: + output = run_cmd(podman_machine_list).stdout.decode("utf-8").strip() + if "running" not in output: + return False + output = run_cmd(conman_args).stdout.decode("utf-8").strip() if output == "krunkit" or output == "libkrun": return True + except subprocess.CalledProcessError: pass @@ -59,11 +65,6 @@ def use_container(): if sys.platform == "darwin": conman = container_manager() krunkit_configured = ai_support_in_vm(conman) - if krunkit_configured: - print(f"Running in a container via {conman}") - else: - print("Running natively on macOS") - return krunkit_configured return True