fixing get inconsistency and adding vm_state_command

This commit is contained in:
2021-02-16 21:13:51 -06:00
parent 2e265703bd
commit e8348052a8
6 changed files with 87 additions and 14 deletions

View File

@ -1,3 +1,4 @@
#!/bin/sh
vmname="$1"
@ -7,10 +8,13 @@ if echo "$vmname" | grep -vqE '^(cvm|capsul)-[a-z0-9]{10}$'; then
exit 1
fi
if ! virsh list --name --all | grep -qE "^$vmname$" ; then
echo "Error: $vmname not found"
exit 1
# this will let us know if the vm exists or not
exists="false"
if virsh domuuid "$vmname" | grep -vqE '^[\t\s\n]*$'; then
exists="true"
fi
# this gets the ipv4
virsh domifaddr "$vmname" | awk '/vnet/ {print $4}' | cut -d'/' -f1
ipv4="$(virsh domifaddr "$vmname" | awk '/vnet/ {print $4}' | cut -d'/' -f1)"
echo "$exists $ipv4"