diff options
author | Martin Schwenke <martin@meltin.net> | 2014-07-02 11:56:54 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2014-07-02 20:26:52 +1000 |
commit | a24dcfc63f5074f2971c869b24880dc77c2f3232 (patch) | |
tree | 11f24c931a437b425f2d0153a9d00a49dbe38fb6 /autocluster | |
parent | 55d315b1118283c60edaf365ef9b123eaea27bed (diff) | |
download | autocluster-a24dcfc63f5074f2971c869b24880dc77c2f3232.tar.gz autocluster-a24dcfc63f5074f2971c869b24880dc77c2f3232.tar.xz autocluster-a24dcfc63f5074f2971c869b24880dc77c2f3232.zip |
Add create_node_DEFAULT, no more hack_nodes_functions
Reduce the amount of work needed to define how to create a new node
type.
* Each node type definition needs to define node_name_format_<TYPE>()
* Node types that should be part of the CTDB cluster should define
node_is_ctdb_node_<TYPE>() and have it echo 1
* Nodes need not define create_node_<TYPE>() if they don't do anything
unusual.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'autocluster')
-rwxr-xr-x | autocluster | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/autocluster b/autocluster index e621b56..25756b5 100755 --- a/autocluster +++ b/autocluster @@ -151,6 +151,11 @@ for_each_node () done } +node_is_ctdb_node_DEFAULT () +{ + echo 0 +} + hack_one_node_with () { local filter="$1" ; shift @@ -213,6 +218,18 @@ clear_hooks () # the same disk. hack_disk_hooks="" +create_node_DEFAULT () +{ + local type="$1" + local ip_offset="$2" + local name="$3" + local ctdb_node="$4" + + echo "Creating node \"$name\" (of type \"${type}\")" + + create_node_COMMON "$name" "$ip_offset" "$type" +} + # common node creation stuff create_node_COMMON () { @@ -346,9 +363,8 @@ make_network_map () ############################## -hack_nodes_functions= - -expand_nodes () { +expand_nodes () +{ # Expand out any abbreviations in NODES. local ns="" local n @@ -374,12 +390,6 @@ expand_nodes () { done NODES="$ns" - # Apply nodes hacks. Some of this is about backward compatibility - # but the hacks also fill in the node names and whether they're - # part of the CTDB cluster. The order is the order that - # configuration modules register their hacks. - run_hooks hack_nodes_functions - # Check IP addresses for duplicates. local ip_offsets=":" # This function doesn't modify anything... @@ -390,6 +400,23 @@ expand_nodes () { ip_offsets="${ip_offsets}${ip_offset}:" } hack_all_nodes_with get_ip_offset + + # Determine node names and whether they're in the CTDB cluster + declare -A node_count + _get_name_ctdb_node () + { + local count=$((${node_count[$node_type]:-0} + 1)) + node_count[$node_type]=$count + local fmt + fmt=$(call_func node_name_format "$node_type") || \ + die "Node type \"${node_type}\" not defined!!!" + # printf behaves weirdly if given too many args for format, so + # "head" handles the case where there is no %d or similar for + # $count. + name=$(printf "${fmt}" "$CLUSTER" $count | head -n 1) + ctdb_node=$(call_func node_is_ctdb_node "$node_type") + } + hack_all_nodes_with _get_name_ctdb_node } ############################## @@ -414,7 +441,8 @@ common_nodelist_hacking () local sname="" local hosts_line local ip_addr="${NETWORK_PRIVATE_PREFIX}.$(($FIRSTIP + $ip_offset))" - + + # Primary name for CTDB nodes is <CLUSTER>n<num> if [ "$ctdb_node" = 1 ] ; then num_ctdb_nodes=$(($num_ctdb_nodes + 1)) sname="${CLUSTER}n${num_ctdb_nodes}" |