diff options
author | Martin Schwenke <martin@meltin.net> | 2014-06-20 15:36:43 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2014-07-02 14:17:17 +1000 |
commit | 7dc9a243914ca258afbff61d574b0579fb36951b (patch) | |
tree | fac6bf0bf60ad296d8fecd575d05331f6d3099dd /autocluster | |
parent | 5bede7898ff160163c41c278314590fc609a3ad4 (diff) | |
download | autocluster-7dc9a243914ca258afbff61d574b0579fb36951b.tar.gz autocluster-7dc9a243914ca258afbff61d574b0579fb36951b.tar.xz autocluster-7dc9a243914ca258afbff61d574b0579fb36951b.zip |
Add new commands cluster [ destroy | update_hosts | boot ]
Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'autocluster')
-rwxr-xr-x | autocluster | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/autocluster b/autocluster index a003980..1f62441 100755 --- a/autocluster +++ b/autocluster @@ -54,7 +54,7 @@ EOF commands: base [ create | boot ] ... - cluster create + cluster [ destroy | create | update_hosts | boot ] ... create base create a base image @@ -510,6 +510,67 @@ cluster_created_hosts_message () register_hook cluster_created_hooks cluster_created_hosts_message +cluster_destroy () +{ + announce "cluster destroy \"${CLUSTER}\"" + [ -n "$CLUSTER" ] || die "\$CLUSTER not set" + + vircmd destroy "$CLUSTER" || true +} + +cluster_update_hosts () +{ + announce "cluster update_hosts \"${CLUSTER}\"" + [ -n "$CLUSTER" ] || die "\$CLUSTER not set" + + [ -n "$hosts_file" ] || hosts_file="tmp/hosts.${CLUSTER}" + [ -r "$hosts_file" ] || die "Missing hosts file \"${hosts_file}\"" + + local pat="# autocluster ${CLUSTER}\$|[[:space:]]${CLUSTER}(n|base)[[:digit:]]+" + + local t="/etc/hosts.${CLUSTER}" + grep -E "$pat" /etc/hosts >"$t" || true + if diff -B "$t" "$hosts_file" >/dev/null ; then + rm "$t" + return + fi + + local old=/etc/hosts.old.autocluster + cp /etc/hosts "$old" + local new=/etc/hosts.new + grep -Ev "$pat" "$old" | + cat -s - "$hosts_file" >"$new" + + mv "$new" /etc/hosts + + echo "Made these changes to /etc/hosts:" + diff -u "$old" /etc/hosts || true +} + +cluster_boot () +{ + [ -n "$CLUSTER_PATTERN" ] || CLUSTER_PATTERN="$CLUSTER" + announce "cluster boot \"${CLUSTER_PATTERN}\"" + [ -n "$CLUSTER_PATTERN" ] || die "\$CLUSTER_PATTERN not set" + + vircmd start "$CLUSTER_PATTERN" + + local nodes=$(vircmd dominfo "$CLUSTER_PATTERN" 2>/dev/null | \ + sed -n -e 's/Name: *//p') + + # Wait for each node + local i + for i in $nodes ; do + waitfor "${KVMLOG}/serial.$i" "login:" 300 || { + vircmd destroy "$CLUSTER_PATTERN" + die "Failed to create cluster" + } + done + + # Move past the last line of log output + echo "" +} + create_one_node () { CLUSTER="$1" @@ -1296,7 +1357,8 @@ case "$t" in actions_init for t in "$@" ; do case "$t" in - create) actions_add "cluster_${t}" ;; + destroy|create|update_hosts|boot) + actions_add "cluster_${t}" ;; *) usage ;; esac done |