summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Runner <gitlab-runner@greyhound.leap.se>2016-07-16 18:30:48 +0000
committerGitLab Runner <gitlab-runner@greyhound.leap.se>2016-07-16 18:30:48 +0000
commit80faa0016d00654e31d4c5daadf1b0e96821f72e (patch)
tree881361a094d93a2a8ad451a04119f11ed48553c4
parent9caa44a9b8a348cf889f99908cddabc98d4d4274 (diff)
Add remove_stale_vms
-rwxr-xr-xremove_stale_vms18
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
+