Rename vm_id field and add list helpers
This commit is contained in:
parent
eedc1fe1d8
commit
6aa191663a
4 changed files with 49 additions and 2 deletions
|
|
@ -38,7 +38,7 @@ reboot
|
||||||
|
|
||||||
## VM Info File
|
## VM Info File
|
||||||
Each VM writes a metadata file at `state/vm-*/info` with the following fields:
|
Each VM writes a metadata file at `state/vm-*/info` with the following fields:
|
||||||
- `vm_id`: unique identifier for the VM instance.
|
- `id`: unique identifier for the VM instance.
|
||||||
- `pid`: Firecracker process ID.
|
- `pid`: Firecracker process ID.
|
||||||
- `created_at`: timestamp when the VM was launched.
|
- `created_at`: timestamp when the VM was launched.
|
||||||
- `guest_ip`: IP address assigned to the guest.
|
- `guest_ip`: IP address assigned to the guest.
|
||||||
|
|
|
||||||
24
list.sh
Executable file
24
list.sh
Executable 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
|
||||||
23
ps.sh
Executable file
23
ps.sh
Executable file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/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")"
|
||||||
|
|
||||||
|
if [[ -z "$pid" || -z "$api_sock" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ps -p "$pid" -o comm=,args= 2>/dev/null | rg -q "firecracker.*--api-sock $api_sock"; then
|
||||||
|
printf 'id=%s name=%s created_at=%s guest_ip=%s pid=%s tap=%s\n' \
|
||||||
|
"$id" "$name" "$created_at" "$guest_ip" "$pid" "$tap"
|
||||||
|
fi
|
||||||
|
done
|
||||||
2
run.sh
2
run.sh
|
|
@ -355,7 +355,7 @@ log "starting virtual machine"
|
||||||
VM_STARTED=1
|
VM_STARTED=1
|
||||||
|
|
||||||
cat > "$VM_DIR/info" <<EOF
|
cat > "$VM_DIR/info" <<EOF
|
||||||
vm_id=$VM_ID
|
id=$VM_ID
|
||||||
name=$VM_NAME
|
name=$VM_NAME
|
||||||
pid=$FC_PID
|
pid=$FC_PID
|
||||||
created_at=$(date -Iseconds)
|
created_at=$(date -Iseconds)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue