first try at implementing the vm start and stop feature

This commit is contained in:
2021-02-17 20:50:17 -06:00
parent e8348052a8
commit ba0b29462c
9 changed files with 296 additions and 159 deletions

View File

@ -10,11 +10,27 @@ fi
# this will let us know if the vm exists or not
exists="false"
if virsh domuuid "$vmname" | grep -vqE '^[\t\s\n]*$'; then
state = "unknown"
if ! virsh domuuid "$vmname" | grep -qE '^[\t\s\n]*$'; then
exists="true"
state_code="$(virsh domstats $vmname | grep state.state | cut -d '=' -f 2)"
if ! printf "$state_code" | grep -qE '^[0-8]$'; then
printf 'state_code was not detected. state_code %s must match ^[0-8]$\n' "$state_code"
exit 1
fi
case "$state_code" in
1) state = "running" ;;
2) state = "blocked" ;;
4) state = "stopping" ;;
6) state = "crashed" ;;
[357]) state = "stopped" ;;
esac
fi
# this gets the ipv4
ipv4="$(virsh domifaddr "$vmname" | awk '/vnet/ {print $4}' | cut -d'/' -f1)"
echo "$exists $ipv4"
echo "$exists $state $ipv4"