#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2000,2005 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)33 1.35 src/avs/fs/mmfs/ts/admin/mmlscluster.sh, mmfs, avs_rgpfs24, rgpfs240610b 8/11/05 01:46:29
##########################################################################
#
#  List data for the nodes that belong to a GPFS cluster.
#
#  Usage:  mmlscluster
#
##########################################################################

# Include global declarations and service routines.
. /usr/lpp/mmfs/bin/mmglobfuncs
. /usr/lpp/mmfs/bin/mmsdrfsdef

sourceFile="mmlscluster.sh"
[[ -n $DEBUG || -n $DEBUGmmlscluster ]] && set -x
$mmTRACE_ENTER "$*"

# Local work files.  Names should be of the form:
#   fn=${tmpDir}fn.${mmcmd}.$$

LOCAL_FILES=" "

# Local variables
usageMsg=357
firstFreenode=yes

underline="----------------------------------------------------------"
underline="${underline}----------------------------------------------"
dblunderline="======================================================="
dblunderline="${dblunderline}========================================"


#############################
# Check the input arguments.
#############################
[[ $arg1 = '-?' || $arg1 = '-h' || $arg1 = '--help' || $arg1 = '--' ]] &&  \
  syntaxError "help" $usageMsg

[[ $argc -ge 1 ]] &&  \
  syntaxError "extraArg"  $usageMsg "$arg1"


#######################################################################
# Set up trap exception handling and call the gpfsInit function.
# It will ensure that the local copy of the mmsdrfs and the rest
# of the GPFS system files are up-to-date.  No need to lock the sdr.
#######################################################################
trap pretrap2 HUP INT QUIT KILL
gpfsInitOutput=$(gpfsInit nolock)
setGlobalVar $? $gpfsInitOutput


##################################################################
# Determine the value of the uidDomain parameter.  We do this
# separately because the value is not kept in the version line
# while we want to display it early in the mmlscluster output.
##################################################################
uidDomain=$(showCfgValue uidDomain)


##################################################################
# Prepare the mmsdrfs file.  This involves an additional sorting
# to assure that the node numbers come out in numerical order.
##################################################################
LC_ALL=C $sort -t: -k 1,1 -k 3,3 -k 2,2 -k 5,5n -k 4,4n $mmsdrfsFile -o $tmpsdrfs
checkForErrors sort $?


################################
# Display the principal header.
################################
header=$(printInfoMsg 400)
printf "\n%s\n%.${#header}s\n" "$header" "$dblunderline"


###############################################
# Display the information in the mmsdrfs file.
###############################################
IFS=":"
exec 3<&-
exec 3< $tmpsdrfs
while read -u3 sdrfsLine
do
  # Parse the line.
  set -f ; set -A v -- - $sdrfsLine ; set +f
  IFS="$IFS_sv"

  # Display information from some of the fields depending on the type of line.
  case ${v[$LINE_TYPE_Field]} in

    $VERSION_LINE )
      # Ensure we have the correct paths for the remote commands.
      [[ -z ${v[$RSH_PATH_Field]} || ${v[$RSH_PATH_Field]} = "_DEFAULT_" ]] && \
        v[$RSH_PATH_Field]=$rsh
      [[ -z ${v[$RCP_PATH_Field]} || ${v[$RCP_PATH_Field]} = "_DEFAULT_" ]] && \
        v[$RCP_PATH_Field]=$rcp

      # Display the GPFS cluster type and id.
      printInfoMsg 430 ${v[$CLUSTER_NAME_Field]}
      printInfoMsg 434 ${v[$CLUSTERID_Field]}

      # Display the UID domain value.
      [[ -z $uidDomain ]] && uidDomain=${v[$CLUSTER_NAME_Field]}
      printInfoMsg 451 $uidDomain

      # If this is not a single node cluster,
      # display remote command paths, network information, etc.
      if [[ $environmentType != single ]]
      then
        # Display the remote commands in effect.
        printInfoMsg 435 ${v[$RSH_PATH_Field]}
        printInfoMsg 436 ${v[$RCP_PATH_Field]}

        # Display the primary and secondary servers.
        header=$(printInfoMsg 401)
        printf "\n%s\n%.${#header}s\n" "$header" "$underline"
        printInfoMsg 402 ${v[$PRIMARY_SERVER_Field]}
        [[ -z ${v[$BACKUP_SERVER_Field]} || ${v[$BACKUP_SERVER_Field]} = "_NOSECONDARY_" ]] &&  \
          v[$BACKUP_SERVER_Field]=$(printInfoMsg 409)
        printInfoMsg 403 ${v[$BACKUP_SERVER_Field]}
      fi  # end if [[ $environmentType != single ]]

      # Display the header line for the node information.
      # " Node  Daemon node name   IP address  Admin node name  Designation"
      header=$(printInfoMsg 404)
      printf "\n%s\n%.${#header}s\n" "$header" "$underline"
      ;;

    $MEMBER_NODE )

      if [[ ${v[$CORE_QUORUM_Field]} = $quorumNode ]]
      then
        if [[ ${v[$DESIGNATION_Field]} = $MANAGER ]]
        then
          nodeRole=$(printInfoMsg 414)  # "quorum-manager"
        else
          nodeRole=$(printInfoMsg 475)  # "quorum"
        fi
      else
        if [[ ${v[$DESIGNATION_Field]} = $MANAGER ]]
        then
          nodeRole=$(printInfoMsg 482)  # "manager"
        else
          nodeRole=""
        fi
      fi

      if [[ -n ${v[$DAEMON_NODENAME_Field]} ]]
      then
        daemonNodeName=${v[$DAEMON_NODENAME_Field]}
      else
        daemonNodeName=${v[$REL_HOSTNAME_Field]}
      fi
 
      printf "%4s %1s %-27s %-16s %-27s %s\n"  \
             "${v[$NODE_NUMBER_Field]}" "$BLANKchar" "$daemonNodeName"  \
             "${v[$IPA_Field]}" "${v[$REL_HOSTNAME_Field]}" "$nodeRole"
      ;;

    * )  # No need to look at any of the other lines.
      ;;

  esac  # end of Display information from some of the fields

  IFS=":"  # Change the separator back to ":" for the next iteration.

done  # end of while read -u3 sdrfsLine

IFS="$IFS_sv"  # Restore the default IFS settings.


######################
# Cleanup and return.
######################
print ""                   # Add a blank line for nicer formatting.
cleanupAndExit 0

