diff options
| author | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2024-12-22 19:03:49 +0800 |
| commit | f7f159a04671690786de2f84e34046c103521d58 (patch) | |
| tree | 22b45e904c1aa6800250ec6e998d0022fd018ade /others/vm3/compute/delete.sh | |
| parent | 2916e3eff503473f6bf8b90e0921b0ccd347166f (diff) | |
vm.shupdate
Diffstat (limited to 'others/vm3/compute/delete.sh')
| -rwxr-xr-x | others/vm3/compute/delete.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/others/vm3/compute/delete.sh b/others/vm3/compute/delete.sh new file mode 100755 index 0000000..dd65379 --- /dev/null +++ b/others/vm3/compute/delete.sh | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # Check if VMs are provided | ||
| 4 | if [ $# -eq 0 ]; then | ||
| 5 | echo "Error: No VM names provided. Usage: $0 vm1 vm2 vm3" | ||
| 6 | exit 1 | ||
| 7 | fi | ||
| 8 | |||
| 9 | # List VMs to be removed | ||
| 10 | echo "The following VMs will be permanently destroyed:" | ||
| 11 | for vm in "$@"; do | ||
| 12 | echo "- $vm" | ||
| 13 | done | ||
| 14 | |||
| 15 | # Confirmation prompt | ||
| 16 | read -p "Are you sure you want to remove these VMs? (y/N): " confirmation | ||
| 17 | if [[ ! "$confirmation" =~ ^[Yy]$ ]]; then | ||
| 18 | echo "Operation cancelled." | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | |||
| 22 | for vm in "$@"; do | ||
| 23 | sudo virsh destroy "$vm" &>/dev/null | ||
| 24 | sudo virsh undefine "$vm" --remove-all-storage &>/dev/null | ||
| 25 | sudo rm -rf "/var/lib/libvirt/images/${vm}" &>/dev/null | ||
| 26 | printf "%-50s%10s\n" "Removing $vm..." $([[ $? -eq 0 ]] && echo "Successful" || echo "Failed") | ||
| 27 | done | ||
