Eventscripts: 10.interface clean-ups - variable name fix-ups.
authorMartin Schwenke <martin@meltin.net>
Tue, 28 Jun 2011 06:50:47 +0000 (16:50 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 12 Aug 2011 05:57:34 +0000 (15:57 +1000)
Change most of the uppercase variable names to lowercase for
consistency with other variables, readability and so they can be
easily distinguished from environment/configuration variables.  Change
the name of 2 of the variabless to add some clarity.  Changes are as
follows:

  INTERFACES   -> all_interfaces
  IFACES       -> ctdb_interfaces
  IFACE        -> iface
  I            -> i
  REALIFACE    -> realiface

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/10.interface

index f998a6492bb28321cba557644af458bb7a5a4a39..6443f415e533b0fdcdf7936d013cf88ec034062c 100755 (executable)
@@ -30,79 +30,80 @@ mark_down ()
 
 monitor_interfaces()
 {
-       INTERFACES=`cat $CTDB_PUBLIC_ADDRESSES |
+       all_interfaces=`cat $CTDB_PUBLIC_ADDRESSES |
                sed -e "s/^[^\t ]*[\t ]*//" -e "s/,/ /g" -e "s/[\t ]*$//"`
 
-       [ "$CTDB_PUBLIC_INTERFACE" ] && INTERFACES="$CTDB_PUBLIC_INTERFACE $INTERFACES"
-       [ "$CTDB_NATGW_PUBLIC_IFACE" ] && INTERFACES="$CTDB_NATGW_PUBLIC_IFACE $INTERFACES"
+       [ "$CTDB_PUBLIC_INTERFACE" ] && all_interfaces="$CTDB_PUBLIC_INTERFACE $all_interfaces"
+       [ "$CTDB_NATGW_PUBLIC_IFACE" ] && all_interfaces="$CTDB_NATGW_PUBLIC_IFACE $all_interfaces"
 
 
        # For all but the 1st line, get the 2nd last field with commas
        # changes to spaces.
-       IFACES=`ctdb -Y ip -v | sed -e '1d' -e 's/:[^:]*:$//' -e 's/^.*://' -e 's/,/ /g'`
+       ctdb_ifaces=`ctdb -Y ip -v | sed -e '1d' -e 's/:[^:]*:$//' -e 's/^.*://' -e 's/,/ /g'`
 
-       INTERFACES=`for IFACE in $INTERFACES $IFACES ; do echo $IFACE ; done | sort | uniq`
+       all_interfaces=`for iface in $all_interfaces $ctdb_ifaces ; do echo $iface ; done | sort | uniq`
 
        fail=false
        up_interfaces_found=false
-       for IFACE in $INTERFACES ; do
 
-           ip addr show $IFACE 2>/dev/null >/dev/null || {
-               echo Interface $IFACE does not exist but it is used by public addresses.
+       for iface in $all_interfaces ; do
+
+           ip addr show $iface 2>/dev/null >/dev/null || {
+               echo Interface $iface does not exist but it is used by public addresses.
                continue
            }
 
            # These interfaces are sometimes bond devices
            # When we use VLANs for bond interfaces, there will only
            # be an entry in /proc for the underlying real interface
-           REALIFACE=`echo $IFACE |sed -e 's/\..*$//'`
-           bi=$(get_proc "net/bonding/$REALIFACE" 2>/dev/null) && {
+           realiface=`echo $iface |sed -e 's/\..*$//'`
+           bi=$(get_proc "net/bonding/$realiface" 2>/dev/null) && {
                echo "$bi" | grep -q 'Currently Active Slave: None' && {
-                       echo "ERROR: No active slaves for bond device $REALIFACE"
-                       mark_down $IFACE
+                       echo "ERROR: No active slaves for bond device $realiface"
+                       mark_down $iface
                        continue;
                }
                echo "$bi" | grep -q '^MII Status: up' || {
-                       echo "ERROR: public network interface $REALIFACE is down"
-                       mark_down $IFACE
+                       echo "ERROR: public network interface $realiface is down"
+                       mark_down $iface
                        continue;
                }
                echo "$bi" | grep -q '^Bonding Mode: IEEE 802.3ad Dynamic link aggregation' && {
                        echo "$bi" | grep 'MII Status:' | tail -n +2 | grep -q '^MII Status: up' || {
-                               echo No active slaves for 802.ad bond device $REALIFACE
-                               mark_down $IFACE
+                               echo No active slaves for 802.ad bond device $realiface
+                               mark_down $iface
                                continue
                        }
                }
-               mark_up $IFACE
+               mark_up $iface
                continue;
            }
 
-           case $IFACE in
+           case $iface in
            lo*)
                # loopback is always working
-               mark_up $IFACE
+               mark_up $iface
                ;;
            ib*)
                # we dont know how to test ib links
-                mark_up $IFACE
+               mark_up $iface
                ;;
            *)
-               [ -z "$IFACE" ] || {
-                   [ "$(basename $(readlink /sys/class/net/$IFACE/device/driver) 2>/dev/null)" = virtio_net ] ||
-                   ethtool $IFACE | grep -q 'Link detected: yes' || {
+               [ -z "$iface" ] || {
+                   [ "$(basename $(readlink /sys/class/net/$iface/device/driver) 2>/dev/null)" = virtio_net ] ||
+                   ethtool $iface | grep -q 'Link detected: yes' || {
                        # On some systems, this is not successful when a
                        # cable is plugged but the interface has not been
                        # brought up previously. Bring the interface up and
                        # try again...
-                       ip link set $IFACE up
-                       ethtool $IFACE | grep -q 'Link detected: yes' || {
-                           echo "ERROR: No link on the public network interface $IFACE"
-                           mark_down $IFACE
+                       ip link set $iface up
+                       ethtool $iface | grep -q 'Link detected: yes' || {
+                           echo "ERROR: No link on the public network interface $iface"
+                           mark_down $iface
                            continue
                        }
                    }
-                   mark_up $IFACE
+                   mark_up $iface
                }
                ;;
            esac