commands:
base [ create | boot ] ...
- cluster create
+ cluster [ destroy | create | update_hosts | boot ] ...
create base
create a base image
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"
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