summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-09 20:09:50 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-09 20:09:50 +0300
commitdcd8839c1d602cd35b3ed85b91500337999b6a4c (patch)
tree5795f39bc534c673dc832aaa17f5aef379428207 /create-vm
parent0505986743df1ec93e9eda2f4c0e102350de7e8a (diff)
downloadansibleness-dcd8839c1d602cd35b3ed85b91500337999b6a4c.tar.gz
Fixes for exolobe2
Diffstat (limited to 'create-vm')
-rwxr-xr-xcreate-vm43
1 files changed, 26 insertions, 17 deletions
diff --git a/create-vm b/create-vm
index 92bd0ee..57d3206 100755
--- a/create-vm
+++ b/create-vm
@@ -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