diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-09 20:09:50 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-09 20:09:50 +0300 |
commit | dcd8839c1d602cd35b3ed85b91500337999b6a4c (patch) | |
tree | 5795f39bc534c673dc832aaa17f5aef379428207 /create-vm | |
parent | 0505986743df1ec93e9eda2f4c0e102350de7e8a (diff) | |
download | ansibleness-dcd8839c1d602cd35b3ed85b91500337999b6a4c.tar.gz |
Fixes for exolobe2
Diffstat (limited to 'create-vm')
-rwxr-xr-x | create-vm | 43 |
1 files changed, 26 insertions, 17 deletions
@@ -57,23 +57,32 @@ virt-install --connect qemu:///system \ --import \ --os-variant=debianwheezy \ --disk="path=$lvpath,cache=none" \ - --network=network=default \ + --network="$vmnetwork" \ --graphics=spice \ --noautoconsole -# Get the MAC address. -mac="$(virsh -c qemu:///system dumpxml "$name" | - sed -n "/<mac address=/s/^.*'\(.*\)'.*/\1/p")" - -# Get IP address related to the MAC address. Append that to /etc/hosts. -leases=/var/lib/libvirt/dnsmasq/default.leases -ip="" -while [ "$ip" = "" ] -do - sleep 1 - ip="$(awk -v "mac=$mac" '$2 == mac { print $3 }' "$leases")" -done -echo "$ip $name" | sudo tee -a /etc/hosts > /dev/null - -# Done. -echo "Virtual machine $name ($ip) has been created and started." +# If we're using the virtual network "default", wait for the VM to get +# a DHCP response and add it to /etc/hosts. We don't do it for other +# types of network (e.g., bridge=br0), since we ... can't. + +if [ "$vmnetwork" = "network=default" ] +then + # Get the MAC address. + mac="$(virsh -c qemu:///system dumpxml "$name" | + sed -n "/<mac address=/s/^.*'\(.*\)'.*/\1/p")" + + # Get IP address related to the MAC address. Append that to /etc/hosts. + leases=/var/lib/libvirt/dnsmasq/default.leases + ip="" + while [ "$ip" = "" ] + do + sleep 1 + ip="$(awk -v "mac=$mac" '$2 == mac { print $3 }' "$leases")" + done + echo "$ip $name" | sudo tee -a /etc/hosts > /dev/null + + # Done. + echo "Virtual machine $name ($ip) has been created and started." +else + echo "Virtual machien $name has been created and started, and may be ready soon." +fi |