#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_list_hosts.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_list_hosts # # Description: This is the main, FPATH function that is invoked by clmgr # to list host names from within the cluster. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: The list array is populated with one host per entry. The # only other outputs are any error messages that might be # needed. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_list_hosts { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : INPUTS: $* typeset -n list=$1 shift [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -A queries typeset -u attr= typeset -l TYPE="" typeset item= hosts= value= typeset -i index=0 matches=0 rc=$RC_UNKNOWN while (( $# > 0 )); do value="$1" if [[ $value == *=* ]]; then attr=${value%%=*} # "attr" makes this uppercase if [[ $attr == "TYPE" ]];then TYPE="${value#*=}" shift continue fi queries[$attr]="${value#*=}" fi shift done #=================================================== : Check for any specified attribute=value pairs. : If any are found, use those to query the output. #=================================================== while (( $# > 0 )); do value="$1" if [[ $value == *=* ]]; then attr=${value%%=*} # "attr" makes this uppercase queries[$attr]="${value#*=}" fi shift done if (( ${#queries[*]} == 0 )); then # List all if [[ -n $TYPE ]] then CL=$LINENO verify_in_set TYPE "$TYPE" "CAA CANDIDATES POTENTIAL SMIT" TYPE fi if (( $? == RC_SUCCESS )); then case $TYPE in caa) print "$0()[$LINENO]($SECONDS): lscluster -m | grep \"Node name:\"" >>$CLMGR_TMPLOG hosts=$(LC_ALL=C lscluster -m | grep "Node name:") rc=$? print "$0()[$LINENO]($SECONDS): lscluster -m | grep \"Node name:\" RC == $rc ($hosts)" >>$CLMGR_TMPLOG print -- "$hosts" |\ while read item do list[$index]=${item#*: } (( index++ )) done ;; @(candidates|potential|smit)) list_candidates $TYPE rc=$? ;; *) CL=$LINENO isClusterDefined if (( $? == RC_SUCCESS )); then print "$0()[$LINENO]($SECONDS): clnodename" >>$CLMGR_TMPLOG # Always log commands hosts=$(clodmget -q "object=COMMUNICATION_PATH" -n -f value HACMPnode) rc=$? print "$0()[$LINENO]($SECONDS): clnodename RC: $rc; hosts == \"${hosts//+([[:space:]])/, }\"" >>$CLMGR_TMPLOG # Always log command result (( $rc != RC_SUCCESS )) && rc=$RC_ERROR for item in $hosts; do list[$index]=$item (( index++ )) done fi ;; esac else rc=$RC_INCORRECT_INPUT fi else # A search was specified typeset -A allProperties CL=$LINENO CLMGR_VERBOSE=1 KLIB_HACMP_get_host_attributes allProperties CL=$LINENO search_properties queries allProperties rc=$? if (( $rc == RC_SUCCESS )); then for key in ${!allProperties[*]}; do [[ $key != HOSTNAME@(|+([0-9])) ]] && continue list[$index]=${allProperties[$key]} (( index++ )) done fi fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_list_hosts()" #============================================================================ # # Name: KLIB_HACMP_list_candidates # # Description: This is a helper function that lists -potential- hosts # for the cluster. This is done by finding the intersection # between /etc/hosts and /etc/cluster/rhosts, and filtering # out addresses that are already known to be in use in the # cluster. # # Inputs: See the "TYPE" description in the "devDoc()" function, below. # # Outputs: The results are displayed directly on STDOUT. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function list_candidates { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : INPUTS: $* typeset -l TYPE=$1 # : The communication path for a new node cannot : be the communication path for an existing node, : or an interface on any existing node. Concatenate : existing values into a string to use with egrep # current_paths=$(clodmget -q 'object = COMMUNICATION_PATH' -f value -n HACMPnode | paste -s -d'|' -) current_ips=$(clodmget -f identifier -n HACMPadapter | paste -s -d'|' -) if [[ -n $current_ips ]] then current_paths=${current_paths:+$current_paths\|}$current_ips fi host $(hostname) | read localname is localip rest if [[ "|$current_paths|" != *\|$localname\|* ]]; then current_paths=${current_paths:+$current_paths\|}$localname fi if [[ "|$current_paths|" != *\|$localip\|* ]]; then current_paths=${current_paths:+$current_paths\|}$localip fi # : The communication path for a new node must exist in : /etc/cluster/rhosts. Since rhosts can contain IP : addresses or labels, we must form the list as follows: # rhost_paths=$(cat /etc/cluster/rhosts | while read i; do [[ -z $i ]] && continue host $i 2>/dev/null | sed 's/,//' | read ip is label rest [[ -n $ip ]] && echo "$ip#$label" done | paste -s -d'|' -) # : And finally gather everything in /etc/hosts # etchosts_paths=$(clgetinterfaces -h | cut -f3,5 -d'#' | \ grep -vw loopback | paste -s -d'|' -) if [[ $TYPE == @(candidates|smit) ]] then # # The rhosts and etc hosts entries are all formatted # into a string like label#ip|label#ip|... # : Now for the presentation: : show everything in rhosts that : is not already in the HA config # for path in ${rhost_paths//\|/ } do echo ${path%%#*} | egrep -qvw "$current_paths|loopback" && \ echo ${path#*#} | egrep -qvw "$current_paths" && \ echo $path | sed 's/\(.*\)#\(.*\)/\1 (\2)/' done if [[ $TYPE == "smit" ]] then # : In case the above code did not produce the expected results, : give some clues by displaying "potential" entries below. : This should provide the same output as the SMIT panel pick list. # print " # $(dspmsg -s 40 cluster.cat 201 "# Don't see what you are looking for ?\n") # $(dspmsg -s 40 cluster.cat 202 "# To add a node, you must first create entries in\n# /etc/hosts and /etc/cluster/rhosts.\n") #" # : Show the potential entries in comments, where "potential" means the : entries are defined in /etc/hosts, but not /etc/cluster/rhosts, and : are not already known to the cluster. # integer banner=1 typeset rhosts_egrep=${rhost_paths//#/'|'} for entry in ${etchosts_paths//\|/ } do if echo ${entry%%#*} | egrep -qvw "$rhosts_egrep" && \ echo ${entry#*#} | egrep -qvw "$rhosts_egrep" && \ echo ${entry%%#*} | egrep -qvw "$current_paths" && \ echo ${entry#*#} | egrep -qvw "$current_paths" then if (( banner )) then dspmsg -s 40 cluster.cat 203 "# The following entries in /etc/hosts do not exist\n# in /etc/cluster/rhosts:\n#\n" banner=0 fi echo "# $(echo $entry | sed 's/\(.*\)#\(.*\)/\1 (\2)/')" fi done fi elif [[ $TYPE == "potential" ]] then # : For "POTENTIAL" hosts, we are looking for entries that are : defined in /etc/hosts, but not /etc/cluster/rhosts. # typeset rhosts_egrep=${rhost_paths//#/'|'} for entry in ${etchosts_paths//\|/ } do if echo ${entry%%#*} | egrep -qvw "$rhosts_egrep" && \ echo ${entry#*#} | egrep -qvw "$rhosts_egrep" && \ echo ${entry%%#*} | egrep -qvw "$current_paths" && \ echo ${entry#*#} | egrep -qvw "$current_paths" then echo $entry | sed 's/\(.*\)#\(.*\)/\1 (\2)/' fi done fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "list_candidates()" #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose. This feature was originally implemented # using the man page information. However, in a code review it # was pointed out that this approach had to be changed because # customers do not have to install the man pages! Therefore, a # built-in dependency on man page information would break the # automatic help feature of clmgr. So the SYNPOSIS section must # be used instead. # # IMPORTANT: As a result of this, it is imperative that the # information in this SYNOPSIS be kept in sync # with the man page information, which is owned # by the IDD team. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_list_hosts =head1 SYNOPSIS clmgr query node NOTE: the alias for "node" is "no". =head1 DESCRIPTION Displays the currently configured set of hosts. =head1 ARGUMENTS 1. list [REQUIRED] [hash ref] An associative array within which data about the queried objects can be returned to the caller. 2. TYPE [OPTIONAL] [set] An optional indicator of what type of hosts to list. By default, the communication paths from the cluster are listed. But the following types will change the output: * "CAA" Lists the CAA host members. * "CANDIDATES" Lists the entries that are common to /etc/hosts and /etc/cluster/rhosts, but are not already in use in the cluster. * "POTENTIAL" Lists the entries that are defined in /etc/hosts, but not in /etc/cluster/rhosts, and are not already in use in the cluster. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =head1 COPYRIGHT COPYRIGHT International Business Machines Corp. 2006,2015 All Rights Reserved =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================