2021-02-18 03:22:01 +00:00
|
|
|
#!/bin/sh -e
|
2020-05-10 23:59:30 +00:00
|
|
|
|
|
|
|
vmname="$1"
|
|
|
|
|
2020-05-13 18:56:43 +00:00
|
|
|
if echo "$vmname" | grep -vqE '^(cvm|capsul)-[a-z0-9]{10}$'; then
|
2020-05-10 23:59:30 +00:00
|
|
|
echo "vmname $vmname must match "'"^capsul-[a-z0-9]{10}$"'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-02-17 03:13:51 +00:00
|
|
|
# this will let us know if the vm exists or not
|
|
|
|
exists="false"
|
2021-02-18 03:22:01 +00:00
|
|
|
state="unknown"
|
2021-02-18 03:19:27 +00:00
|
|
|
if virsh domuuid "$vmname" | grep -vqE '^[\t\s\n]*$'; then
|
2021-02-17 03:13:51 +00:00
|
|
|
exists="true"
|
2021-02-18 02:50:17 +00:00
|
|
|
|
|
|
|
state_code="$(virsh domstats $vmname | grep state.state | cut -d '=' -f 2)"
|
|
|
|
|
2021-02-18 03:19:27 +00:00
|
|
|
if printf "$state_code\n" | grep -vqE '^[0-8]$'; then
|
2021-02-18 02:50:17 +00:00
|
|
|
printf 'state_code was not detected. state_code %s must match ^[0-8]$\n' "$state_code"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$state_code" in
|
2021-02-18 03:22:01 +00:00
|
|
|
1) state="running" ;;
|
|
|
|
2) state="blocked" ;;
|
|
|
|
4) state="stopping" ;;
|
|
|
|
6) state="crashed" ;;
|
|
|
|
[357]) state="stopped" ;;
|
2021-02-18 02:50:17 +00:00
|
|
|
esac
|
2020-05-10 23:59:30 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# this gets the ipv4
|
2021-08-04 00:56:55 +00:00
|
|
|
ipv4="$(virsh domifaddr "$vmname" | awk '/ipv4/ {print $4}' | cut -d'/' -f1)"
|
2021-02-17 03:13:51 +00:00
|
|
|
|
2021-02-18 02:50:17 +00:00
|
|
|
echo "$exists $state $ipv4"
|