node_name_format_* functions should produce the node name
authorMartin Schwenke <martin@meltin.net>
Mon, 28 Jul 2014 10:06:16 +0000 (20:06 +1000)
committerMartin Schwenke <martin@meltin.net>
Mon, 28 Jul 2014 10:06:16 +0000 (20:06 +1000)
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>
autocluster
config.d/50node_nas.defconf
config.d/51node_rhel_base.defconf
config.d/52node_build.defconf
config.d/55node_storage_gpfs.defconf
config.d/57node_ad.defconf
config.d/60tsm.defconf

index 94d942e9c3236db2b3a983a10ae394065ff8970d..30bce13a1e06ab8f282d4551fcc71c36e35ec693 100755 (executable)
@@ -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")
index 65c14fded247de768b74bad4af20468894cb5829..2b19b5668b4213922f9167f5fb32ad20349cef27 100644 (file)
@@ -2,7 +2,10 @@
 
 node_name_format_nas ()
 {
-    echo '%snas%d'
+    local cluster="$1"
+    local index="$2"
+
+    printf '%snas%d' "$cluster" "$index"
 }
 
 node_is_ctdb_node_nas ()
index ddb90b5661dafae57668e81af91c5541763aa268..65e98d3ed5ac49ab8333c2e35094c0bba2667b0c 100644 (file)
@@ -2,5 +2,8 @@
 
 node_name_format_rhel_base ()
 {
-    echo '%sbase%d'
+    local cluster="$1"
+    local index="$2"
+
+    printf '%sbase%d' "$cluster" "$index"
 }
index c9fc3e03f9cd4b1daf39fe2fa3f30dd77f7d96f4..c58123e7712e17c92e126471cf17c55b3754b289 100644 (file)
@@ -2,7 +2,10 @@
 
 node_name_format_build ()
 {
-    echo '%sbuild%d'
+    local cluster="$1"
+    local index="$2"
+
+    printf '%sbuild%d' "$cluster" "$index"
 }
 
 cluster_setup_tasks_build ()
index 08f9811ffa8a081f0621f58eeb0b5a51513e0a93..fb4bfc5aa69245fc88c79355fe357734e63f4fcf 100644 (file)
@@ -4,7 +4,10 @@ NODES_STORAGE_GPFS=
 
 node_name_format_storage_gpfs ()
 {
-    echo '%sstorage%d'
+    local cluster="$1"
+    local index="$2"
+
+    printf '%sstorage%d' "$cluster" "$index"
 }
 
 create_node_storage_gpfs ()
index 8cc791c9a8e31f41b7534000586333db003df2e2..4e69829e50af0ba92e163a87b2efd73b0c8277c1 100644 (file)
@@ -11,7 +11,10 @@ defconf AD_NETBIOS_NAME "samba4" \
 
 node_name_format_ad ()
 {
-    echo '%sad%d'
+    local cluster="$1"
+    local index="$2"
+
+    printf '%sad%d' "$cluster" "$index"
 }
 
 cluster_setup_tasks_ad ()
index c831188448a344c3c38eaa896e74bbb41538e7f8..2dd6dc59d6123e8a21b89cdc495098ac49f06eca 100644 (file)
@@ -27,11 +27,14 @@ defconf TSM_TEMPLATE "$installdir/templates/tsmserver.xml" \
 
 node_name_format_tsm ()
 {
+    local cluster="$1"
+    local index="$2"
+
     # If only 1 tsm_server node then don't number it.
     if [ "${NODES/tsm_server:/}" = "${NODES//tsm_server:/}" ] ; then
-       echo '%stsm'
+       printf '%stsm' "$cluster"
     else
-       echo '%stsm%d'
+       printf '%stsm%d' "$cluster" "$index"
     fi
 }