#!/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_get_hmc_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_hmc_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect HMC information. The cllshmc utility is invoked # to extract the necessary data. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: The properties hash is populated. 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_get_hmc_attributes { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_hmc_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset hmcs=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then hmcs= typeset -n properties=$1 else typeset -n properties=$2 fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset -i INDEX=0 rc=$RC_UNKNOWN typeset key= hmc= HMCS= typeset hmc_label= timeout= retry_count= retry_delay= nodename= sitename= username= password= typeset -i matches=0 typeset -u attr= uc_key= typeset -A queries typeset -i i=0 typeset -i CONN_TYPE=0 typeset -i incluster=0 /usr/lib/cluster/incluster 2>/dev/null (( $? == RC_SUCCESS )) && incluster=1 #=================================================== : 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 #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY #======================================= : Make sure we have something to query #======================================= elif [[ -n $hmcs ]]; then [[ $hmcs != *,* ]] && unset INDEX for hmc in ${hmcs//,/ }; do CL=$LINENO KLIB_HACMP_is_known_hmc hmc if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$hmc" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 174 "Available HMCs:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_hmcs available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" rc=$RC_NOT_FOUND else HMCS="${HMCS:+$HMCS }$hmc" fi done elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then typeset available CL=$LINENO KLIB_HACMP_list_hmcs available rc=$? for (( i=0; i<${#available[*]}; i++ )); do HMCS="${HMCS:+$HMCS }${available[$i]}" done else dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT fi (( rc != RC_SUCCESS && rc != RC_UNKNOWN )) && unset HMCS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for HMC in $HMCS; do typeset NODES= typeset HMC_PROPERTIES= print -- "$0()[$LINENO]($SECONDS): cllshmc -c -u $HMC" >>$CLMGR_TMPLOG # Always log commands HMC_PROPERTIES=$(cllshmc -c -u $HMC) rc=$? print -- "$0()[$LINENO]($SECONDS): cllshmc -c -u $HMC rc=$rc" >>$CLMGR_TMPLOG # Always log commands result if (( $rc == RC_SUCCESS )); then print -- "$HMC_PROPERTIES" |\ while IFS=: read hmc_label timeout retry_count retry_delay user passwd rem do [[ $hmc_label == \#* ]] && continue # Skip the column headers properties[NAME$INDEX]=$hmc_label properties[TIMEOUT$INDEX]=$timeout properties[RETRY_COUNT$INDEX]=$retry_count properties[RETRY_DELAY$INDEX]=$retry_delay properties[USER_NAME$INDEX]=$user properties[PASSWORD$INDEX]=$passwd typeset -i cmd_rc= #NODES typeset NODENAMES= print -- "$0()[$LINENO]($SECONDS): cllshmcparam -m $HMC -o" >>$CLMGR_TMPLOG # Always log commands NODENAMES=$(cllshmcparam -m $HMC -o) rc=$? print -- "$0()[$LINENO]($SECONDS): cllshmcparam -m $HMC -o rc=$rc" >>$CLMGR_TMPLOG # Always log commands result if (( $rc == RC_SUCCESS )); then for NODENAME in $NODENAMES; do NODES="${NODES:+$NODES }$NODENAME" done properties[NODES$INDEX]=$NODES fi #SITES if [[ $CLUSTER_TYPE != "NSC" ]]; then typeset SITES= typeset SITENAMES= print -- "$0()[$LINENO]($SECONDS): cllssite -H $HMC" >>$CLMGR_TMPLOG # Always log commands SITENAMES=$(cllssite -H $HMC) cmd_rc=$? print -- "$0()[$LINENO]($SECONDS): cllssite -H $HMC cmd_rc=$cmd_rc" >>$CLMGR_TMPLOG # Always log commands result if (( $cmd_rc == RC_SUCCESS )); then for SITENAME in $SITENAMES; do SITES="${SITES:+$SITES }$SITENAME" done properties[SITES$INDEX]=$SITES fi # Continue even if no site, having dumped cmd_rc to log. fi print "$0()[$LINENO]($SECONDS):CONN_TYPE=$(clodmget -n -f connection_type HACMPhmcparam)" >>$CLMGR_TMPLOG # Always log command result CONN_TYPE=$(clodmget -n -f connection_type HACMPhmcparam >> $CLMGR_TMPLOG 2>&1) cmd_rc=$? print "$0()[$LINENO]($SECONDS): clodmget RC: $cmd_rc connection_type = $CONN_TYPE" >>$CLMGR_TMPLOG # Always log command result typeset hmccmd= if (( $CONN_TYPE == 1 )); then hmccmd="clrest" else hmccmd="clhmccmd" fi #hmc version typeset VERSION= print -- "$0()[$LINENO]($SECONDS): $hmccmd -o query -a hmc_version -H $hmc_label" >>$CLMGR_TMPLOG # Always log commands VERSION=$($hmccmd -o query -a hmc_version -H $hmc_label 2>>$CLMGR_TMPLOG) cmd_rc=$? print -- "$0()[$LINENO]($SECONDS): $hmccmd -o query -a hmc_version -H $hmc_label cmd_rc=$cmd_rc" >>$CLMGR_TMPLOG # Always log commands result if (( $cmd_rc == RC_SUCCESS )); then properties[STATUS$INDEX]="UP" properties[VERSION$INDEX]="$VERSION" else properties[STATUS$INDEX]="DOWN" fi # Continue even if VERSION is DOWN, having dumped cmd_rc to log. done #============================================================== : Even if there is no value for a given attribute, we want to : display a placeholder for it, so the customer always sees a : consistent, complete set of attributes. #============================================================== for key in ${_COLON_ATTR_ORDER[cod]}; do if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) fi done #========================================================== : If any searches/filters were specified, handle them now #========================================================== if (( $rc == RC_SUCCESS && ${#queries[*]} > 0 )); then CL=$LINENO search_properties queries properties rc=$? fi (( rc == RC_SUCCESS )) && CL=$LINENO prune_indexes properties log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_get_hmc_attributes()" #============================================================================ # # 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_get_hmc_attributes =head1 VERSION Version Number: 1.5.1.9 Last Extracted: 8/9/16 14:12:29 Last Changed: 7/28/16 10:20:32 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_hmc_attributes.sh, hacmp.assist, 61haes_r721, 1631A_hacmp721 =head1 SYNOPSIS clmgr query hmc [[,,...]] clmgr -v query hmc =head1 DESCRIPTION Retrieves the data for one or more HMCs defined within the cluster configuration. =head1 ARGUMENTS 1. HMC [REQUIRED] [string] The label of one or more HMCs (comma or space separated) that are to be queried. 2. properties [REQUIRED] [hash ref] An associative array within which data about the queried objects can be returned to the caller. =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. 2012,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 #==============================================================================