This commit is contained in:
Stephen Simpson
2025-11-26 08:15:00 -06:00
parent 3cbd4525a0
commit bb829c9b63
18 changed files with 2440 additions and 349 deletions

View File

@@ -1,5 +1,6 @@
#!/bin/bash
set -e
# Note: Not using 'set -e' here because we handle errors explicitly
# and arithmetic operations can cause false failures with set -e
VM_NAME="$1"
GOLDEN_IMAGE="$2"
@@ -20,7 +21,7 @@ sudo qemu-img create -f qcow2 -b "$GOLDEN_IMAGE" -F qcow2 "$VM_DISK" 2>/dev/null
# Define and start VM
echo "[Provision] Starting VM with virt-install..."
sudo virt-install \
VIRT_INSTALL_OUTPUT=$(sudo virt-install \
--name "$VM_NAME" \
--memory 2048 \
--vcpus 2 \
@@ -31,14 +32,21 @@ sudo virt-install \
--noautoconsole \
--wait 0 \
--transient \
2>&1 | grep -v "WARNING" || true
2>&1) || {
echo "[Provision] ERROR: virt-install failed"
echo "$VIRT_INSTALL_OUTPUT" | grep -v "WARNING"
echo "[Provision] Cleaning up disk..."
sudo rm -f "$VM_DISK"
echo "ERROR"
exit 1
}
# Wait for IP address
echo "[Provision] Waiting for VM to obtain IP address (max ${MAX_WAIT}s)..."
COUNTER=0
while [ $COUNTER -lt $MAX_WAIT ]; do
# Try to get IP from DHCP lease
IP=$(sudo virsh domifaddr "$VM_NAME" --source lease 2>/dev/null | awk '/ipv4/ {print $4}' | cut -d/ -f1 | head -1)
# Try to get IP from DHCP lease (explicitly use system connection)
IP=$(sudo virsh -c qemu:///system domifaddr "$VM_NAME" --source lease 2>/dev/null | awk '/ipv4/ {print $4}' | cut -d/ -f1 | head -1)
if [ -n "$IP" ] && [ "$IP" != "0.0.0.0" ]; then
echo "[Provision] IP obtained: $IP"