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

24
logs.sh
View file

@ -13,23 +13,17 @@ Prints the Firecracker log for a VM. Use --follow to tail -f.
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
@ -76,8 +70,8 @@ if [[ -z "$QUERY" ]]; then
exit 1
fi
INFO_FILE="$(find_vm_info "$QUERY")"
LOG_FILE="$(get_prop "$INFO_FILE" "log")"
VM_JSON="$(find_vm_json "$QUERY")"
LOG_FILE="$(jq -r '.meta.log // empty' "$VM_JSON")"
if [[ -z "$LOG_FILE" || ! -f "$LOG_FILE" ]]; then
log "log file not found: $LOG_FILE"