Store VM metadata as JSON

This commit is contained in:
Thales Maciel 2026-01-31 23:17:12 -03:00
parent bbd57d8dd2
commit 7af04b7535
No known key found for this signature in database
GPG key ID: 33112E6833C34679
11 changed files with 188 additions and 178 deletions

30
kill.sh
View file

@ -13,23 +13,17 @@ Sends a signal to the Firecracker process.
EOF
}
get_prop() {
local info="$1"
local key="$2"
awk -F= -v k="$key" '$1==k {print $2}' "$info"
}
find_vm_info() {
find_vm_json() {
local query="$1"
local info match_count=0 match=""
local vm_json match_count=0 match=""
for info in state/vms/*/info; do
[[ -f "$info" ]] || continue
for vm_json in state/vms/*/vm.json; do
[[ -f "$vm_json" ]] || continue
local id name
id="$(get_prop "$info" "id")"
name="$(get_prop "$info" "name")"
id="$(jq -r '.meta.id // empty' "$vm_json")"
name="$(jq -r '.meta.name // empty' "$vm_json")"
if [[ "$id" == "$query"* || "$name" == "$query"* ]]; then
match="$info"
match="$vm_json"
match_count=$((match_count + 1))
fi
done
@ -75,15 +69,15 @@ if [[ -z "$QUERY" || "$QUERY" == "-h" || "$QUERY" == "--help" ]]; then
exit 1
fi
INFO_FILE="$(find_vm_info "$QUERY")"
PID="$(get_prop "$INFO_FILE" "pid")"
API_SOCK="$(get_prop "$INFO_FILE" "api_sock")"
VM_JSON="$(find_vm_json "$QUERY")"
PID="$(jq -r '.meta.pid // empty' "$VM_JSON")"
API_SOCK="$(jq -r '.meta.api_sock // empty' "$VM_JSON")"
if [[ -z "$PID" ]]; then
log "pid not found in $INFO_FILE"
log "pid not found in $VM_JSON"
exit 1
fi
if [[ -z "$API_SOCK" ]]; then
log "api_sock not found in $INFO_FILE"
log "api_sock not found in $VM_JSON"
exit 1
fi