summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-03-16 15:21:19 +1100
committerAmitay Isaacs <amitay@gmail.com>2015-03-16 15:49:59 +1100
commit604ac38ad38f7b920b72b8011d8ada0896aacac0 (patch)
treeea65316124d640794028a65a731c6e2b395d585f
parentea99d69a193cac8e1a34992a993941dd428aeb5e (diff)
downloadautocluster-604ac38ad38f7b920b72b8011d8ada0896aacac0.tar.gz
autocluster-604ac38ad38f7b920b72b8011d8ada0896aacac0.tar.xz
autocluster-604ac38ad38f7b920b72b8011d8ada0896aacac0.zip
Remove internal use of vircmd
It is too easy to clobber/interact with domains that are no specified in the cluster configuration. Replace use of vircmd with new function virsh_cluster(). The only possible loss here is that unmatched nodes may not be destroyed, so duplicate IP addresses might occur when cluster configuration changes. To try to avoid this a warning is printed by virsh_cluster() when domains that are not part of the cluster are found to match CLUSTER/CLUSTER_PATTERN. Signed-off-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-xautocluster60
1 files changed, 52 insertions, 8 deletions
diff --git a/autocluster b/autocluster
index 60d2e97..dafc605 100755
--- a/autocluster
+++ b/autocluster
@@ -183,6 +183,52 @@ hack_all_nodes_with ()
NODES="$nodes"
}
+list_all_cluster_nodes ()
+{
+ # Local function only defined in subshell
+ (
+ print_node_name ()
+ {
+ echo "$3"
+ }
+ for_each_node print_node_name
+ ) | sort
+}
+
+list_all_virsh_domains ()
+{
+ local pattern="${CLUSTER_PATTERN:-${CLUSTER}[a-z]*[0-9]}"
+
+ local domains=$(virsh list --all | awk '{print $2}' | tail -n +3)
+ local d
+ for d in $domains ; do
+ case "$d" in
+ ($pattern) echo "$d" ;;
+ esac
+ done | sort
+}
+
+virsh_cluster ()
+{
+ local command="$1"
+
+ local nodes=$(list_all_cluster_nodes)
+ local domains=$(list_all_virsh_domains)
+
+ if [ "$nodes" != "$domains" ] ; then
+ echo "WARNING: Found matching virsh domains that are not part of this cluster!"
+ echo
+ fi
+
+ local ret=0
+ local n
+ for n in $nodes ; do
+ virsh "$command" "$n" 2>&1 || ret=$?
+ done
+
+ return $ret
+}
+
register_hook ()
{
local hook_var="$1"
@@ -547,7 +593,7 @@ cluster_destroy ()
announce "cluster destroy \"${CLUSTER}\""
[ -n "$CLUSTER" ] || die "\$CLUSTER not set"
- vircmd destroy "$CLUSTER" || true
+ virsh_cluster destroy || true
}
cluster_undefine ()
@@ -555,7 +601,7 @@ cluster_undefine ()
announce "cluster undefine \"${CLUSTER}\""
[ -n "$CLUSTER" ] || die "\$CLUSTER not set"
- vircmd undefine "$CLUSTER" || true
+ virsh_cluster undefine || true
}
cluster_update_hosts ()
@@ -603,14 +649,12 @@ cluster_update_hosts ()
cluster_boot ()
{
- [ -n "$CLUSTER_PATTERN" ] || CLUSTER_PATTERN="$CLUSTER"
- announce "cluster boot \"${CLUSTER_PATTERN}\""
- [ -n "$CLUSTER_PATTERN" ] || die "\$CLUSTER_PATTERN not set"
+ announce "cluster boot \"${CLUSTER}\""
+ [ -n "$CLUSTER" ] || die "\$CLUSTER not set"
- vircmd start "$CLUSTER_PATTERN"
+ virsh_cluster start || return $?
- local nodes=$(vircmd dominfo "$CLUSTER_PATTERN" 2>/dev/null | \
- sed -n -e 's/Name: *//p')
+ local nodes=$(list_all_cluster_nodes)
# Wait for each node
local i