#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2019,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_repository_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_repository_attributes # # Description: This is the main, FPATH function that is invoked by # clmgr to collect repository disk information. Part of # the information is collected directly in this function, # and the remainder is collected via the standard physical # volume code, "KLIB_HACMP_get_physical_volume_attributes". # # 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_repository_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_repository_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset repositories=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then repositories= typeset -n properties=$1 typeset site=$2 else typeset -n properties=$2 typeset site=$3 fi [[ $site == *=* ]] && site="" [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset INDEX= name= value= repository= key= SITES= typeset -i matches=0 rc=$RC_UNKNOWN i=0 typeset -u attr= uc_key= typeset STATUS="" typeset -A queries REPOSITORIES ODM_DATA NODE_MAP typeset ACTIVE= BACKUPS= DISK_DATA= LSCLUSTER_D="" LSDEV_L="" typeset -i INDEX=1 BACKUP_SEQ=1 USER_SPECIFIED_SITE=0 if [[ $repositories == *\)* ]]; then repositories=${repositories//\)+([[:space:]])/\),} else repositories=${repositories//+([[:space:]])/,} fi typeset repos_array integer j=0 IFS=, for repos in $repositories do repos=${repos##*([[:space:]])} repos=${repos%%*([[:space:]])} repos=${repos//+([[:space:]])/ } if [[ $repos != *([[:space:]]) ]]; then repos_array[$j]="$repos" (( j++ )) fi done IFS="$ORIG_IFS" #=================================================== : 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 [[ -n $site ]]; then queries[SITE]=$site USER_SPECIFIED_SITE=1 fi #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY fi if [[ $site != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_site "$site" >/dev/null if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$site" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 157 "Available Sites:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_sites 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 fi fi if (( $rc != RC_UNKNOWN )); then log_return_msg "$rc" "$0()" "$LINENO" return $? fi #======================================= : Make sure we have something to query #======================================= if [[ -n $repositories ]]; then typeset KNOWN_REPOSITORIES # A simple, non-associative array CL=$LINENO KLIB_HACMP_list_repositories KNOWN_REPOSITORIES #=========================================================== : Loop through the specified repositories, validating each : one and collecting its set of possible identifiers. #=========================================================== integer r=0 for (( r=0; r<${#repos_array[*]}; r++ )) do repository="${repos_array[$r]}" typeset ORIGINAL_REPOS=$repository if [[ $repository == +([[:alnum:]])\ \(+([[:alnum:]])\) ]] then typeset PVID=${repository#*\(} PVID=${PVID%\)} if (( ${#PVID} == 16 )); then # Since PVIDs are more specific than device names, # use the PVID is both are provided. repository=$PVID fi fi #======================================================== : Attempt to improve the accuracy of ambiguous queries. : If there is exactly one match, use the PVID from that. #======================================================== typeset -i COUNT=0 typeset FOUND=-1 for (( i=0; i<${#KNOWN_REPOSITORIES[*]}; i++ )); do print -- "${KNOWN_REPOSITORIES[$i]}" |\ grep -qw $repository if (( $? == RC_SUCCESS )); then (( COUNT++ )) FOUND=$i fi done if (( COUNT == 1 )) && [[ -n ${KNOWN_REPOSITORIES[$FOUND]#* } ]] then repository=${KNOWN_REPOSITORIES[$FOUND]#* } repository=${repository#\(} repository=${repository%\)} fi : Verify that the specified disk is, in fact, a repository typeset -i cmd_rc=$RC_UNKNOWN if [[ $CLUSTER_TYPE == "LC" ]]; then if [[ -n $site ]]; then CL=$LINENO KLIB_HACMP_is_known_repository "$repository" "$site" 2>/dev/null cmd_rc=$? else typeset SITE= for SITE in $(clodmget -n -f name HACMPsite); do if [[ -n ${_ENV_ARGS[SITE]} && ${_ENV_ARGS[SITE]} != $SITE ]] then continue fi #=================================================== # Hide STDERR here, since we're forced to try all # all known sites... and for sure only one of them # will be correct! Errors from the others are of # no use, and will confuse the customer. #=================================================== CL=$LINENO KLIB_HACMP_is_known_repository "$repository" "$SITE" 2>/dev/null cmd_rc=$? (( $cmd_rc == RC_SUCCESS )) && site=$SITE && break done fi else CL=$LINENO KLIB_HACMP_is_known_repository "$repository" cmd_rc=$? fi if (( $cmd_rc != RC_SUCCESS )); then if [[ -n $site ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 193 '\nERROR: "%1$s" does not appear to exist within site "%2$s", or is not a repository.\n\n' "$ORIGINAL_REPOS" "$site" 1>&2 else dspmsg -s $CLMGR_SET $CLMGR_MSGS 464 '\nERROR: "%1$s" does not appear to exist, or is not a repository.\n\n' "$ORIGINAL_REPOS" 1>&2 fi dspmsg -s $CLMGR_SET $CLMGR_MSGS 168 "Available Repositories:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_repositories 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 typeset IDENTIFIERS= if [[ $CLUSTER_TYPE == "LC" ]]; then typeset SITE=$site if [[ -n $SITE ]]; then NODES=$(clodmget -n -f nodelist -q name=$SITE HACMPsite) #=========================================== : If the user specified a particular node, : try to honor that request #=========================================== if [[ -n ${queries[NODE]} && \ " ${NODES//,/ } " == *\ ${queries[NODE]}\ * ]] then NODES=${queries[NODE]} fi CL=$LINENO getDiskData "$repository" "$NODES" IDENTIFIERS true if (( $? == RC_SUCCESS )); then typeset rep_name= rep_pvid= rep_uuid= print -- "$IDENTIFIERS" | IFS=: read rep_name rep_pvid rep_uuid typeset ODMDATA=$(clodmget -n -q name=${SITE}_sircol HACMPsircol) if [[ -n $ODMDATA && $ODMDATA == *${rep_pvid}* ]] then NODE_MAP[_$rep_pvid]="$NODES" fi fi else for SITE in $(clodmget -n -f name HACMPsite); do NODES=$(clodmget -n -f nodelist -q name=$SITE HACMPsite) #=========================================== : If the user specified a particular node, : try to honor that request #=========================================== if [[ -n ${queries[NODE]} && \ " ${NODES//,/ } " == *\ ${queries[NODE]}\ * ]] then NODES=${queries[NODE]} fi #=================================================== # Hide STDERR here, since we're forced to try all # all known sites... and for sure only one of them # will be correct! Errors from the others are of # no use, and will confuse the customer. #=================================================== CL=$LINENO getDiskData "$repository" "$NODES" IDENTIFIERS true 2>/dev/null if (( $? == RC_SUCCESS )); then typeset rep_name= rep_pvid= rep_uuid= print -- "$IDENTIFIERS" | IFS=: read rep_name rep_pvid rep_uuid typeset ODMDATA=$(clodmget -n -q name=${SITE}_sircol HACMPsircol) if [[ -n $ODMDATA && $ODMDATA == *${rep_pvid}* ]] then NODE_MAP[_$rep_pvid]="$NODES" fi fi done fi else #=========================================== : If the user specified a particular node, : try to honor that request #=========================================== typeset REFNODE="" if [[ -n ${queries[NODE]} ]]; then REFNODE=${queries[NODE]} else REFNODE=$LOCAL_NODE fi typeset rep_name= rep_pvid= rep_uuid= CL=$LINENO getDiskData "$repository" "$REFNODE" IDENTIFIERS true print -- "$IDENTIFIERS" | IFS=: read rep_name rep_pvid rep_uuid NODE_MAP[_$rep_pvid]="$NODES" fi fi (( ! USER_SPECIFIED_SITE )) && site="" # Reset done # End of the user-specified repository loop elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then typeset available CL=$LINENO KLIB_HACMP_list_repositories available NODE_MAP 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_UNKNOWN )) && unset NODE_MAP #==================================== : Get the repositories from the ODM #==================================== if [[ $CLUSTER_TYPE == "LC" ]]; then CL=$LINENO KLIB_HACMP_list_sites SITES for (( i=0; i<${#SITES[*]}; i++ )); do ACTIVE=$(clodmget -n -q name="${SITES[$i]}_sircol" -f repository HACMPsircol) ACTIVE=${ACTIVE//0000000000000000/} BACKUPS=$(clodmget -n -q name="${SITES[$i]}_sircol" -f backup_repository HACMPsircol) BACKUPS=${BACKUPS//0000000000000000/} REPOSITORIES[_$ACTIVE]=$BACKUPS done else ACTIVE=$(clodmget -n -f repository HACMPsircol) ACTIVE=${ACTIVE//0000000000000000/} BACKUPS=$(clodmget -n -f backup_repository HACMPsircol) BACKUPS=${BACKUPS//0000000000000000/} REPOSITORIES[_$ACTIVE]=$BACKUPS fi #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for repository in ${!NODE_MAP[*]}; do typeset NODES=${NODE_MAP[$repository]} NODES=${NODES%%\(*} repository=${repository#_} #===================================================================== : If the user specified a particular node, try to honor that request #===================================================================== if [[ -n ${queries[NODE]} && \ " ${NODES//,/ } " == *\ ${queries[NODE]}\ * ]] then NODES=${queries[NODE]} fi unset DATA typeset -A DATA CL=$LINENO KLIB_HACMP_get_physical_volume_attributes "$repository" DATA "$NODES" ALL for key in ${!DATA[*]}; do properties[${key%+([[:digit:]])}$INDEX]="${DATA[$key]}" done CL=$LINENO getDiskData "$repository" "$NODES" DISK_DATA 1 typeset REPOS_NAME="" REPOS_PVID="" REPOS_UUID="" REFNODE="" REM="" print -- "$DISK_DATA" | IFS=: read REPOS_NAME REPOS_PVID REPOS_UUID REFNODE REM if [[ -n $REFNODE ]]; then properties[NODE$INDEX]=$REFNODE else properties[NODE$INDEX]=${NODES%% *} fi #============================================================= : Get the appropriate HACMPsircol stanza for this repository #============================================================= if [[ $CLUSTER_TYPE == "LC" ]]; then : This is a Linked Cluster, get the site for this repository properties[SITE$INDEX]="" for (( i=0; i<${#SITES[*]}; i++ )); do if [[ -z ${ODM_DATA[${SITES[$i]}]} ]]; then ODM_DATA[${SITES[$i]}]=$(odmget HACMPsircol | grep -p"HACMPsircol:" -w "name = \"${SITES[$i]}_sircol\"") fi if [[ -n $REPOS_PVID ]]; then print -- "${ODM_DATA[${SITES[$i]}]}" | grep -q $REPOS_PVID if (( $? == RC_SUCCESS )); then properties[SITE$INDEX]=${SITES[$i]} break fi fi done elif [[ -z ${ODM_DATA[$CLUSTER_TYPE]} ]]; then ODM_DATA[$CLUSTER_TYPE]=$(odmget HACMPsircol) fi #============================================================ : Determine the correct backup position for this repository #============================================================ if [[ " ${!REPOSITORIES[*]} " == *\ _$REPOS_PVID\ * ]]; then properties[BACKUP$INDEX]=0 # Not a backup; active repository else typeset STANZA= if [[ $CLUSTER_TYPE == "LC" ]]; then typeset site=${properties[SITE$INDEX]} STANZA=${ODM_DATA[$site]} else STANZA=${ODM_DATA[$CLUSTER_TYPE]} fi BACKUPS=$(print -- "$STANZA" | grep -w backup_repository) BACKUPS=${BACKUPS#*\"} BACKUPS=${BACKUPS%\"*} i=1 for name in ${BACKUPS//,/ }; do if [[ ${name%0000000000000000} == $REPOS_PVID ]]; then properties[BACKUP$INDEX]=$i break else (( i++ )) fi done fi #==================================================================== : Retrieve the CAA repository status data from the appropriate node #==================================================================== LSCLUSTER_D=$($CLRSH $REFNODE "LC_ALL=C /usr/sbin/lscluster -d $REPOS_NAME" 2>$TMPDIR/clmgr.KHgra.$$) if (( $? == RC_SUCCESS )); then STATUS=${LSCLUSTER_D##*+([[:space:]])State\ :\ } STATUS=${STATUS%%+([[:space:]])*} if [[ $STATUS == *([[:space:]]) ]]; then STATUS=$(dspmsg -s 21 utilities 4 "UNKNOWN") elif [[ $STATUS == *UP* ]]; then STATUS=$(dspmsg -s 21 utilities 1 "UP") elif [[ $STATUS == *DOWN* ]]; then STATUS=$(dspmsg -s 21 utilities 2 "DOWN") elif [[ $STATUS == *ERROR* ]]; then STATUS=$(dspmsg -s 21 utilities 6 "ERROR") fi else #==================================================================== : If lscluster fails to get the repository status, we : depend on lsdev for the status. #==================================================================== print -- "$LSCLUSTER_D" >> $TMPDIR/clmgr.KHgra.$$ LSDEV_L=$($CLRSH $REFNODE "LC_ALL=C ODMDIR=/etc/objrepos /usr/sbin/lsdev -l $REPOS_NAME -F status" 2>$TMPDIR/clmgr.KHgra.$$) if (( $? == RC_SUCCESS )); then if [[ $LSDEV_L == *Available* ]] && (( ${properties[BACKUP$INDEX]} > 0 )); then STATUS=$(dspmsg -s 21 utilities 1 "UP") else STATUS=$(dspmsg -s 21 utilities 2 "DOWN") fi else STATUS=$(dspmsg -s 21 utilities 4 "UNKNOWN") fi fi rm -f $TMPDIR/clmgr.KHgra.$$ properties[STATUS$INDEX]=$STATUS #============================================================== : 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[repository]}; do [[ $key == "SITE" && $CLUSTER_TYPE != "LC" ]] && continue if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done (( $rc == RC_UNKNOWN )) && rc=$RC_SUCCESS (( INDEX++ )) done (( $rc == RC_UNKNOWN )) && rc=$RC_ERROR #========================================================== : 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_repository_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_repository_attributes =head1 VERSION Version Number: 1.20 Last Extracted: 6/16/15 17:51:08 Last Changed: 6/1/15 14:17:48 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_repository_attributes.sh, hacmp.assist, 61haes_r720, 1525A_hacmp720 =head1 SYNOPSIS clmgr query repository [,,,...] clmgr -v query repository =head1 DESCRIPTION Retrieves the configuration data for one or more repository disks. =head1 ARGUMENTS 1. repository [REQUIRED] [string] The label of one or more repository disks (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 #==============================================================================