fix(smolmachines): stop VM before pack commit, with confirm prompt

smolvm pack create --from-vm requires the VM to be stopped. Add
machine_is_running() to smolvm.py (via machine ls --json state field),
and add the same confirm-stop flow to SmolmachinesFreezer that was
originally designed for macos-container: if running, prompt the user,
stop the VM, then pack. Already-stopped VMs are packed directly.
This commit is contained in:
2026-06-23 08:42:03 +00:00
committed by didericis
parent a32c0c7865
commit d11e3940fa
3 changed files with 89 additions and 6 deletions
+16
View File
@@ -25,6 +25,7 @@ smolvm binary."""
from __future__ import annotations
import json
import shutil
import subprocess
import time
@@ -153,6 +154,21 @@ def machine_create(
_smolvm(*args)
def machine_is_running(name: str) -> bool:
"""Return True if the named VM is in the 'running' state."""
result = _smolvm("machine", "ls", "--json", check=False)
if result.returncode != 0:
return False
try:
machines = json.loads(result.stdout or "[]")
except ValueError:
return False
return any(
isinstance(m, dict) and m.get("name") == name and m.get("state") == "running"
for m in machines
)
def machine_start(name: str) -> None:
"""`smolvm machine start --name NAME`."""
_smolvm("machine", "start", "--name", name)