ctdb-scripts: Rename and relocate function get_all_interfaces()
authorVinit Agnihotri <vagnihotri@ddn.com>
Tue, 30 Jan 2024 09:25:37 +0000 (01:25 -0800)
committerMartin Schwenke <martins@samba.org>
Tue, 16 Apr 2024 23:51:45 +0000 (23:51 +0000)
get_all_interfaces() functions gets all names for all public interfaces.
However name is misleading. Thus renamed it to get_public_ifaces() and
moved it under functions.

Signed-off-by: Vinit Agnihotri <vagnihotri@ddn.com>
Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
ctdb/config/events/legacy/10.interface.script
ctdb/config/functions

index fead88c014ff98accf2101c8505f2f82b33a5803..110b1213966c9f97f50cdb864e87075ded2d211c 100755 (executable)
 
 load_script_options
 
-ctdb_public_addresses="${CTDB_BASE}/public_addresses"
-
-if [ ! -f "$ctdb_public_addresses" ]; then
+if ! have_public_addresses; then
        if [ "$1" = "init" ] ; then
                echo "No public addresses file found"
        fi
        exit 0
 fi
 
-# This sets $all_interfaces as a side-effect.
-get_all_interfaces ()
-{
-    # Get all the interfaces listed in the public_addresses file
-    all_interfaces=$(sed -e '/^#.*/d' \
-                        -e 's/^[^\t ]*[\t ]*//' \
-                        -e 's/,/ /g' \
-                        -e 's/[\t ]*$//' "$ctdb_public_addresses")
-
-    # Get the interfaces for which CTDB has public IPs configured.
-    # That is, for all but the 1st line, get the 1st field.
-    ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
-
-    # Add $ctdb_ifaces and make $all_interfaces unique
-    # Use word splitting to squash whitespace
-    # shellcheck disable=SC2086
-    all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
-}
-
 monitor_interfaces()
 {
-       get_all_interfaces
+       get_public_ifaces
 
        down_interfaces_found=false
        up_interfaces_found=false
@@ -50,7 +29,10 @@ monitor_interfaces()
        # Note that this loop must not exit early.  It must process
        # all interfaces so that the correct state for each interface
        # is set in CTDB using setifacelink.
-       for _iface in $all_interfaces ; do
+       #
+       # public_ifaces set by get_public_ifaces() above
+       # shellcheck disable=SC2154
+       for _iface in $public_ifaces ; do
                if interface_monitor "$_iface" ; then
                        up_interfaces_found=true
                        $CTDB setifacelink "$_iface" up >/dev/null 2>&1
index a40b276e2b854da3794caa139b1b97d4c0f77213..e76082b7cb333c0f0e8d285d0d2831a50828ea37 100755 (executable)
@@ -651,6 +651,30 @@ drop_ip()
        fi
 }
 
+have_public_addresses()
+{
+       [ -f "${CTDB_BASE}/public_addresses" ]
+}
+
+# This sets $public_ifaces as a side-effect.
+get_public_ifaces()
+{
+       # Get all the interfaces listed in the public_addresses file
+       public_ifaces=$(sed -e '/^#.*/d' \
+               -e 's/^[^\t ]*[\t ]*//' \
+               -e 's/,/ /g' \
+               -e 's/[\t ]*$//' "${CTDB_BASE}/public_addresses")
+
+       # Get the interfaces for which CTDB has public IPs configured.
+       # That is, for all but the 1st line, get the 1st field.
+       ctdb_ifaces=$($CTDB -X ifaces | sed -e '1d' -e 's@^|@@' -e 's@|.*@@')
+
+       # Add $ctdb_ifaces and make $public_ifaces unique
+       # Use word splitting to squash whitespace
+       # shellcheck disable=SC2086
+       public_ifaces=$(echo $public_ifaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
+}
+
 drop_all_public_ips()
 {
        # _x is intentionally ignored