Rename vm_id field and add list helpers

This commit is contained in:
Thales Maciel 2026-01-29 13:25:23 -03:00
parent eedc1fe1d8
commit 6aa191663a
No known key found for this signature in database
GPG key ID: 33112E6833C34679
4 changed files with 49 additions and 2 deletions

24
list.sh Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
for info in state/vm-*/info; do
id="$(awk -F= '$1=="id"{print $2}' "$info")"
name="$(awk -F= '$1=="name"{print $2}' "$info")"
created_at="$(awk -F= '$1=="created_at"{print $2}' "$info")"
guest_ip="$(awk -F= '$1=="guest_ip"{print $2}' "$info")"
pid="$(awk -F= '$1=="pid"{print $2}' "$info")"
tap="$(awk -F= '$1=="tap"{print $2}' "$info")"
api_sock="$(awk -F= '$1=="api_sock"{print $2}' "$info")"
status="stale"
if [[ -n "$pid" && -n "$api_sock" ]]; then
if ps -p "$pid" -o comm=,args= 2>/dev/null | rg -q "firecracker.*--api-sock $api_sock"; then
status="running"
fi
fi
printf 'status=%s id=%s name=%s created_at=%s guest_ip=%s pid=%s tap=%s\n' \
"$status" "$id" "$name" "$created_at" "$guest_ip" "$pid" "$tap"
done