Add a tool for cleaning up clusters
authorIustin Pop <iustin@google.com>
Tue, 24 Jun 2008 05:17:25 +0000 (05:17 +0000)
committerIustin Pop <iustin@google.com>
Tue, 24 Jun 2008 05:17:25 +0000 (05:17 +0000)
This tool (that is not installed, just available in the source tree)
helps with cleaning up clusters to a (as much as possible) pristine
state. This helps in preparing for QA runs. By cleaning I mean removing
all instances, logical volumes, nodes, etc. - so this will cause
complete data-loss if it's run on a normal cluster.

Limitations: it only deals with drbd8 and not md (if any md devices are
in use which use drbd devices, they will not be cleaned up). Also the
logic behind the cleaning up is not bulet-proof.

Reviewed-by: ultrotter

devel/Makefile.am
devel/clean-cluster.in [new file with mode: 0644]

index fe2cc43..1977afc 100644 (file)
@@ -1,9 +1,11 @@
-EXTRA_DIST = upload.in
-CLEANFILES = upload
+EXTRA_DIST = upload.in clean-cluster.in
+CLEANFILES = upload clean-cluster
 
-all-local: upload
-upload: upload.in
+all-local: upload clean-cluster
+%: %.in
        sed \
          -e 's#@PREFIX@#$(prefix)#g' \
+         -e 's#@LOCALSTATEDIR@#$(localstatedir)#g' \
+         -e 's#@SYSCONFDIR@#$(sysconfdir)#g' \
        < $< > $@
        chmod u+x $@
diff --git a/devel/clean-cluster.in b/devel/clean-cluster.in
new file mode 100644 (file)
index 0000000..3c761f3
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+# Copyright (C) 2008 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+# This is a test script to ease development by cleaning up a cluster
+# as good as possible. This mean it will cause data loss if run by
+# mistake, and thus it should not be used to update production
+# environments. It needs to be run on the master node.
+
+# Usage: clean-cluster --yes-do-it
+
+# Steps performed:
+# - xen instances are destroyed
+# - drbd devices are stopped
+# - all volumes from the xenvg volume group are removed
+# - all nodes are removed from the cluster
+# - the cluster is destroyed
+
+if [ "$1" != "--yes-do-it" ]; then
+    echo "This is a tool designed to 'cleanup' clusters." 1>&2
+    echo "This means complete dataloss." 1>&2
+    echo "Read the source to find out how to call it." 1>&2
+    exit 1
+fi
+
+echo "Removing all known instances"
+for instance in `gnt-instance list --no-headers -o name`; do
+    gnt-instance remove -f $instance
+done
+
+echo "Destroying all remaining instances"
+gnt-cluster command \
+    for inst in \
+    \`xm list\|awk \'{print \$2}\' \| grep -v -e ^ID -e ^0$\`\; \
+    do echo domain id \$inst \; xm destroy \$inst \; done
+
+echo "Unmounting all drbds"
+gnt-cluster command \
+    for mpt in \
+    \`mount \| grep /dev/drbd \|awk \'{print \$3 } \'\` \; \
+    do echo mount point \$mpt \; fuser -vkm \$mpt \; umount \$mpt \; done
+
+echo "Shutting down all drbds"
+gnt-cluster command \
+    for minor in \
+    \` cat /proc/drbd \| grep cs: \| grep -v cs:Unconfigured \| \
+    awk -F: \' { print \$ 1 } \' \` \; \
+    do echo drbd minor $\minor \; drbdsetup /dev/drbd\$minor down \; done
+
+echo "Cleaning up xenvg"
+gnt-cluster command lvremove -f xenvg
+
+echo "Removing all nodes"
+for node in `gnt-node list --no-headers -o name` ; do
+    gnt-node remove $node
+done
+
+echo "Destroying cluster"
+gnt-cluster destroy --yes-do-it
+
+echo "Making sure ganeti daemons are stopped"
+@SYSCONFDIR@/init.d/ganeti stop
+
+echo "Cleaning up @LOCALSTATEDIR@/lib/ganeti"
+rm -rf @LOCALSTATEDIR@/lib/ganeti/*
+
+exit 0