Add create_node_DEFAULT, no more hack_nodes_functions
authorMartin Schwenke <martin@meltin.net>
Wed, 2 Jul 2014 01:56:54 +0000 (11:56 +1000)
committerMartin Schwenke <martin@meltin.net>
Wed, 2 Jul 2014 10:26:52 +0000 (20:26 +1000)
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>
autocluster
config.d/00base.defconf
config.d/50node_nas.defconf
config.d/51node_rhel_base.defconf [new file with mode: 0644]
config.d/52node_build.defconf
config.d/55node_storage_gpfs.defconf
config.d/57node_ad.defconf
config.d/60tsm.defconf

index e621b56f95c2f1cbc328985e02cd0ffc3c925467..25756b5abdd66e36fee9e949a6790354eb86ae8a 100755 (executable)
@@ -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}"
index c39026f06b153f994ef356a4df43225e4abd6574..e380fa9e99e11efa8fdc996bf408a11eefa67195 100644 (file)
@@ -528,36 +528,6 @@ defconf CREATE_BASE_TIMEOUT 3600 \
 
 ##############################
 
-register_hook hack_nodes_functions hack_nodes_rhel_base
-
-hack_nodes_rhel_base ()
-{
-    local node_count_rhel_base=0
-    hack_filter ()
-    {
-       case "$node_type" in
-           rhel_base)
-               node_count_rhel_base=$(($node_count_rhel_base + 1))
-               name="${CLUSTER}base${node_count_rhel_base}"
-               # rhel_base nodes are not part of CTDB cluster
-               ctdb_node=0
-           esac
-    }
-    hack_all_nodes_with hack_filter
-}
-
-create_node_rhel_base ()
-{
-    local ip_offset="$1"
-    local name="$2"
-    local ctdb_node="$3"
-
-    echo "Creating RHEL base node $name"
-    create_node_COMMON "$name" "$ip_offset" "$type"
-}
-
-##############################
-
 # Authentication method
 defconf AUTH_METHOD "files" \
     "files|winbind" "authentication method"
index 794c42f5a6e3fc5ae7b558828e14ea1ded9690cc..65c14fded247de768b74bad4af20468894cb5829 100644 (file)
@@ -1,30 +1,13 @@
 # Hey Emacs, this is a -*- shell-script -*- !!!
 
-hack_nodes_nas ()
+node_name_format_nas ()
 {
-    local node_count_nas=0
-    hack_filter ()
-    {
-       if [ "$node_type" = "nas" ] ; then
-           node_count_nas=$(($node_count_nas + 1))
-           name="${CLUSTER}nas${node_count_nas}"
-           ctdb_node=1
-       fi
-    }
-    hack_all_nodes_with hack_filter
+    echo '%snas%d'
 }
 
-register_hook hack_nodes_functions hack_nodes_nas
-
-create_node_nas ()
+node_is_ctdb_node_nas ()
 {
-    local ip_offset="$1"
-    local name="$2"
-    local ctdb_node="$3"
-
-    echo "Creating NAS node $name"
-
-    create_node_COMMON "$name" "$ip_offset" "$type"
+    echo 1
 }
 
 node_has_shared_disks_nas ()
diff --git a/config.d/51node_rhel_base.defconf b/config.d/51node_rhel_base.defconf
new file mode 100644 (file)
index 0000000..ddb90b5
--- /dev/null
@@ -0,0 +1,6 @@
+# Hey Emacs, this is a -*- shell-script -*- !!!
+
+node_name_format_rhel_base ()
+{
+    echo '%sbase%d'
+}
index b375e0c5f854c5f5f28e3f1cf2698d5f41e9bc26..c9fc3e03f9cd4b1daf39fe2fa3f30dd77f7d96f4 100644 (file)
@@ -1,14 +1,8 @@
 # Hey Emacs, this is a -*- shell-script -*- !!!
 
-create_node_build ()
+node_name_format_build ()
 {
-    local ip_offset="$1"
-    local name="$2"
-    local ctdb_node="$3"
-
-    echo "Creating build node $name"
-
-    create_node_COMMON "$name" "$ip_offset" "$type"
+    echo '%sbuild%d'
 }
 
 cluster_setup_tasks_build ()
index 4ed9ebdf627a2bce4761973961feace98b67679b..08f9811ffa8a081f0621f58eeb0b5a51513e0a93 100644 (file)
@@ -2,31 +2,21 @@
 
 NODES_STORAGE_GPFS=
 
-hack_nodes_storage_gpfs ()
+node_name_format_storage_gpfs ()
 {
-    local node_count_storage_gpfs=0
-    hack_filter ()
-    {
-       if [ "$node_type" = "storage_gpfs" ] ; then
-           node_count_storage_gpfs=$(($node_count_storage_gpfs + 1))
-           name="${CLUSTER}storage${node_count_storage_gpfs}"
-           ctdb_node=0
-           local ld=$(echo $DOMAIN | tr 'A-Z' 'a-z')
-           NODES_STORAGE_GPFS="${NODES_STORAGE_GPFS}${NODES_STORAGE_GPFS:+,}${name}.${ld}"
-       fi
-    }
-    hack_all_nodes_with hack_filter
+    echo '%sstorage%d'
 }
 
-register_hook hack_nodes_functions hack_nodes_storage_gpfs
-
 create_node_storage_gpfs ()
 {
     local ip_offset="$1"
     local name="$2"
     local ctdb_node="$3"
 
-    echo "Creating GPFS storage node $name"
+    local ld=$(echo $DOMAIN | tr 'A-Z' 'a-z')
+    NODES_STORAGE_GPFS="${NODES_STORAGE_GPFS}${NODES_STORAGE_GPFS:+,}${name}.${ld}"
+
+    echo "Creating node \"${name}\" (of type \"storage_gpfs\")"
 
     create_node_COMMON "$name" "$ip_offset" "$type"
 }
index 8abeade1d443ee3cd225549aa633cb9e9cb7aaea..8cc791c9a8e31f41b7534000586333db003df2e2 100644 (file)
@@ -9,6 +9,11 @@ defconf AD_FUNCTION_LEVEL "2008" \
 defconf AD_NETBIOS_NAME "samba4" \
        "<string>" "NetBIOS name to use for AD server"
 
+node_name_format_ad ()
+{
+    echo '%sad%d'
+}
+
 cluster_setup_tasks_ad ()
 {
     case "$1" in
index e0ed1c6843c7ec8765479ed0e3cce19aa884431d..c831188448a344c3c38eaa896e74bbb41538e7f8 100644 (file)
@@ -25,24 +25,14 @@ defconf TSM_TEMPLATE "$installdir/templates/tsmserver.xml" \
 
 # TSM server node type
 
-register_hook hack_nodes_functions hack_nodes_tsm_server
-
-hack_nodes_tsm_server ()
+node_name_format_tsm ()
 {
-    local node_count_tsm_server=0
     # If only 1 tsm_server node then don't number it.
-    [ "${NODES/tsm_server:/}" = "${NODES//tsm_server:/}" ] && \
-       node_count_tsm_server=""
-    hack_filter ()
-    {
-       if [ "$node_type" = "tsm_server" ] ; then
-           [ -n "$node_count_tsm_server" ] && \
-               node_count_tsm_server=$(($node_count_tsm_server + 1))
-           name="${CLUSTER}tsm${node_count_tsm_server}"
-           ctdb_node=0
-       fi
-    }
-    hack_all_nodes_with hack_filter
+    if [ "${NODES/tsm_server:/}" = "${NODES//tsm_server:/}" ] ; then
+       echo '%stsm'
+    else
+       echo '%stsm%d'
+    fi
 }
 
 create_node_tsm_server ()
@@ -55,7 +45,7 @@ create_node_tsm_server ()
     # template needs the value of TSMDISK.
     TSMDISK="${VIRTBASE}/${CLUSTER}/${name}storage.qcow2"
 
-    echo "Creating TSM server node $name"
+    echo "Creating node \"${name}\" (of type \"tsm_server\""
     create_node_COMMON "$name" "$ip_offset" "$type" "$TSM_TEMPLATE"
 
     local di="$TSMDISK"
@@ -63,7 +53,7 @@ create_node_tsm_server ()
        di=$(readlink "$TSMDISK")
     fi
 
-    echo "Creating tsm disk"
+    echo "Creating TSM disk"
     qemu-img create -f qcow2 "$di" $TSMDISKSIZE
 
     echo