summaryrefslogtreecommitdiffstats
path: root/autocluster
diff options
context:
space:
mode:
Diffstat (limited to 'autocluster')
-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