adding metal3 vm verifier
[icn.git] / deploy / metal3-vm / vm-setup / roles / libvirt / files / get-domain-ip.sh
1 #!/bin/sh
2
3 # This script will attempt to get the ip address of the a given libvirt guest.
4
5 set -eu
6
7 PATH=$PATH:/usr/sbin:/sbin
8
9 VMNAME=$1
10
11 # Get the MAC address of the first interface by looking for looking for the
12 # `<mac address...` line.  Yes, we're parsing XML with awk.  It's probably
13 # safe (because the XML is coming from libvirt, so we can be reasonably
14 # confident that the formatting will remain the same).
15 mac=$(virsh dumpxml $VMNAME | awk -F "'" '/mac address/ { print $2; exit }')
16
17 # Look up the MAC address in the ARP table.
18 ip=$(ip neigh | grep $mac | awk '{print $1;}')
19
20 if [ -z "$ip" ]; then
21     echo "vm ip is not available" >&2
22     exit 1
23 fi
24
25 echo $ip