26 lines
673 B
Bash
Executable File
26 lines
673 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
VM_NAME="$1"
|
|
|
|
if [ -z "$VM_NAME" ]; then
|
|
echo "Usage: $0 <vm_name>"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[Cleanup] Starting cleanup for VM: $VM_NAME"
|
|
|
|
# Force stop VM
|
|
echo "[Cleanup] Destroying VM..."
|
|
sudo virsh -c qemu:///system destroy "$VM_NAME" 2>/dev/null || echo "[Cleanup] VM was not running"
|
|
|
|
# Remove VM definition
|
|
echo "[Cleanup] Undefining VM..."
|
|
sudo virsh -c qemu:///system undefine "$VM_NAME" 2>/dev/null || echo "[Cleanup] VM definition already removed"
|
|
|
|
# Remove disk image
|
|
echo "[Cleanup] Removing disk image..."
|
|
sudo rm -f "/var/lib/libvirt/images/${VM_NAME}.qcow2" || echo "[Cleanup] Disk already removed"
|
|
|
|
echo "[Cleanup] Complete for $VM_NAME"
|