summaryrefslogtreecommitdiff
path: root/create-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-05-31 12:14:28 +0300
committerLars Wirzenius <liw@liw.fi>2019-05-31 12:14:28 +0300
commita7d4899e0e0ac5fbeea2c60e1c8d86da01a46746 (patch)
treed8bd9fa6d45117e5c741cf3b1cd207d090908069 /create-vm
parent9f1b04b40c77cca0cc408f840bf137b41d3dd45a (diff)
downloadansibleness-a7d4899e0e0ac5fbeea2c60e1c8d86da01a46746.tar.gz
Fix: create-vm so it works with Debian buster as host
Diffstat (limited to 'create-vm')
-rwxr-xr-xcreate-vm22
1 files changed, 18 insertions, 4 deletions
diff --git a/create-vm b/create-vm
index 519b019..2202eb0 100755
--- a/create-vm
+++ b/create-vm
@@ -27,7 +27,7 @@ leases = json.load(open(sys.argv[1]))
for lease in leases:
if lease["mac-address"] == sys.argv[2]:
print lease["ip-address"]
-' "$1" "$2"
+' "$1" "$2" || true
}
@@ -43,11 +43,12 @@ if [ "$#" != 2 ]
then
die "Usage: $0 NAME BASE"
fi
-
+verbose "Command line args OK"
# Config variables.
. "$HOME/.config/ansibleness/vm.conf"
+verbose "Loaded config file"
# Command line parameters: name of VM and base image (no .img.xz suffix).
name="$1"
@@ -55,6 +56,7 @@ case "$2" in
*/*) basepath="$2" ;;
*) basepath="$imagedir/base-$2.img.xz" ;;
esac
+verbose "basepath=$basepath"
# Does the base image exist?
if [ ! -e "$basepath" ]
@@ -62,28 +64,35 @@ then
echo "$basepath does not exist" 1>&2
exit 1
fi
+verbose "$basepath exists"
# How large is the (uncompressed) image? In bytes.
size="$(xz_uncompressed_size "$basepath")"
+verbose "Image is $size bytes"
# Create new LV.
+verbose "Creating LV /dev/$vg/$name"
sudo lvcreate --name "$name" --size "${size}b" \
--zero y --wipesignatures y --activate y "$vg"
lvpath="/dev/$vg/$name"
+verbose "lvpath=$lvpath"
+#sudo lvchange -ay "$lvpath"
# Copy uncompressed image to LV.
+verbose "Uncompressing and copying image to LV"
unxz < "$basepath" |
pv --size "$size" |
sudo ionice -c3 tee "$lvpath" > /dev/null
# Create VM.
+verbose "Creating VM"
virt-install --connect qemu:///system \
--quiet \
--name="$name" \
--memory=1024 \
--cpu=host-model-only \
--import \
- --os-variant=debianwheezy \
+ --os-variant=debian9 \
--disk="path=$lvpath,cache=none" \
--network="$vmnetwork" \
--graphics=spice \
@@ -95,6 +104,8 @@ virt-install --connect qemu:///system \
if [ "$vmnetwork" = "network=default" ]
then
+ verbose "Waiting for VM to boot and get IP"
+
# Get the MAC address.
mac="$(virsh -c qemu:///system dumpxml "$name" |
sed -n "/<mac address=/s/^.*'\(.*\)'.*/\1/p")"
@@ -107,7 +118,10 @@ then
while [ "$ip" = "" ]
do
sleep 1
- ip="$(get_ip "$leases" "$mac")"
+ if [ -s "$leases" ]
+ then
+ ip="$(get_ip "$leases" "$mac")"
+ fi
done
echo "$ip $name" | sudo tee -a /etc/hosts > /dev/null