diff options
author | Martin Schwenke <martin@meltin.net> | 2014-07-28 20:06:16 +1000 |
---|---|---|
committer | Martin Schwenke <martin@meltin.net> | 2014-07-28 20:06:16 +1000 |
commit | aa02a12144fe70147a22601be9452f43989a62b6 (patch) | |
tree | 97fec48caed8d13750cc7906884a7707572484fc /autocluster | |
parent | 2a42a372ca8c436ecedee03aadb6a0cee44a2d1a (diff) | |
download | autocluster-aa02a12144fe70147a22601be9452f43989a62b6.tar.gz autocluster-aa02a12144fe70147a22601be9452f43989a62b6.tar.xz autocluster-aa02a12144fe70147a22601be9452f43989a62b6.zip |
node_name_format_* functions should produce the node name
No use having them print the format string. That actually makes it
more restrictive. Instead, have the functions take cluster name and
index as arguments - these can then be passed to printf in either
order depending on the format string.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'autocluster')
-rwxr-xr-x | autocluster | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/autocluster b/autocluster index 94d942e..30bce13 100755 --- a/autocluster +++ b/autocluster @@ -407,17 +407,12 @@ expand_nodes () { local count=$((${node_count[$node_type]:-0} + 1)) node_count[$node_type]=$count - local fmt - fmt=$(call_func node_name_format "$node_type") || { + name=$(call_func node_name_format "$node_type" "$CLUSTER" $count) || { echo "ERROR: Node type \"${node_type}\" not defined!" echo "Valid node types are:" set | sed -n 's@^node_name_format_\(.*\) ().*@ \1@p' exit 1 } - # 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 @@ -552,12 +547,9 @@ cluster_update_hosts () # Building a general node name regexp is a bit cumbersome. :-) local name_regexp="(" for i in $(set | sed -n -e "s@^\(node_name_format_.*\) ().*@\1@p") ; do - # For each node_name_format_* function, get the actual node - # name format string - fmt=$($i) - # fill it with placeholders (remembering that "_" is not valid - # in a real cluster name) - local t=$(printf "$fmt\n" "_" "0" | head -n 1) + # Format node name with placeholders (remembering that "_" is + # not valid in a real cluster name) + local t=$("$i" "_" "0") # now replace the placeholders with regexps - order is # important here, since the cluster name can contain digits t=$(sed -r -e "s@[[:digit:]]+@[[:digit:]]+@" -e "s@_@${CLUSTER}@" <<<"$t") |