diff options
author | GitLab Runner <gitlab-runner@greyhound.leap.se> | 2016-07-16 18:30:48 +0000 |
---|---|---|
committer | GitLab Runner <gitlab-runner@greyhound.leap.se> | 2016-07-16 18:30:48 +0000 |
commit | 80faa0016d00654e31d4c5daadf1b0e96821f72e (patch) | |
tree | 881361a094d93a2a8ad451a04119f11ed48553c4 | |
parent | 9caa44a9b8a348cf889f99908cddabc98d4d4274 (diff) |
Add remove_stale_vms
-rwxr-xr-x | remove_stale_vms | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/remove_stale_vms b/remove_stale_vms new file mode 100755 index 0000000..dbcc159 --- /dev/null +++ b/remove_stale_vms @@ -0,0 +1,18 @@ +#!/bin/sh +# +# removes all libvirt domains older than 1 day matching given regex + + +VM_REGEX='$test_' + +remove_domain () { + echo "Destroying and undefining $vm" + virsh destroy "$1" + virsh undefine --remove-all-storage --snapshots-metadata "$1" +} + +for vm in $(find /etc/libvirt/qemu -maxdepth 1 -type f -mmin +1440 -exec basename -s .xml {} \;) +do + [[ "$vm" =~ "$VM_REGEX" ]] && remove_domain $vm +done + |