#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2019,2020,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_network_attributes.sh 1.9 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2006,2015 # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_network_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_get_network_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect network information. The odmget utility is invoked # to extract the necessary data from the HACMPnetwork and # HACMPadapter ODMs. # # 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_network_attributes { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_network_attributes.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset network=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then network= 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 fname= fvalue= ID=0 cluster_id= DATA= MA= typeset -i rc=$RC_UNKNOWN typeset -A alias_values alias_values=( ["1"]="aliased" ["2"]="non-aliased" ) typeset key= typeset -i matches=0 typeset -u attr= uc_key= typeset -A queries typeset -i i=0 : This ensures that the attributes displayed in queries are : identical to those used for add and modify operations. typeset -A ATTRMAP ATTRMAP=( [ATTR]="PUBLIC" [NIMNAME]="TYPE" ) typeset NWS=$network #=================================================== : 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 $network ]]; then NWS= for network in ${network//,/ }; do CL=$LINENO KLIB_HACMP_is_known_network "$network" 2>/dev/null if (( $? != RC_SUCCESS )); then if [[ $CLMGR_PROGNAME == "clmgr" ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$network" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 150 "Available Networks:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_networks available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi rc=$RC_NOT_FOUND else NWS="${NWS:+$NWS }$network" fi done elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then odmget HACMPnetwork | grep -w "name = " |\ while IFS='=' read name value do value=${value##+([[:space:]])} value=${value%%+([[:space:]])} value=${value//\"/} NWS="$NWS $value" done else if [[ $CLMGR_PROGNAME == "clmgr" ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 fi rc=$RC_MISSING_INPUT fi (( $rc != RC_UNKNOWN )) && unset NWS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for network in $NWS; do if [[ $network != $NWS ]] then : We only need this if more than one network is being queried print "$0()[$LINENO]($SECONDS): clodmget -q \"name=$network\" -f network_id HACMPnetwork" >>$CLMGR_TMPLOG # Always log commands ID=$(clodmget -q "name=$network" -f network_id HACMPnetwork) print "$0()[$LINENO]($SECONDS): clodmget RC: $?; ID == \"$ID\"" >>$CLMGR_TMPLOG # Always log command result if (( $ID == 0 )); then ID=$(print -- "$network" | sum) ID=${ID%%+([[:space:]])*} if [[ $ID != +([[:digit:]]) ]]; then ID=$RANDOM fi fi fi #======================================================== : It is important to note that this "GID" value is only : of use in a fully configured, synchronized cluster. : Until then, *all* networks will report an ID of zero, : rendering the GIDs non-unique. #======================================================== print "$0()[$LINENO]($SECONDS): cllsclstr -cS" >>$CLMGR_TMPLOG # Always log commands cluster_id=$(cllsclstr -cS) print "$0()[$LINENO]($SECONDS): cllsclstr RC: $?; cluster_id == \"$cluster_id\"" >>$CLMGR_TMPLOG # Always log command result GID=${cluster_id%%:*}$ID properties[GID$ID]=$GID print "$0()[$LINENO]($SECONDS): odmget -q \"name=$network\" HACMPnetwork" >>$CLMGR_TMPLOG # Always log commands DATA=$(odmget -q "name=$network" HACMPnetwork) print "$0()[$LINENO]($SECONDS): odmget RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" |\ while IFS='=' read fname fvalue; do fname=${fname##+([[:space:]])} fname=${fname%%+([[:space:]])} [[ $fname == "nimname" ]] && fname=TYPE fvalue=${fvalue##+([[:space:]])} fvalue=${fvalue%%+([[:space:]])} fvalue=${fvalue//\"/} if [[ $fname != "HACMPnetwork:" && -n $fname ]]; then uc_key=$fname [[ -n ${ATTRMAP[$uc_key]} ]] && uc_key=${ATTRMAP[$uc_key]} if [[ "$uc_key" == "ALIAS" ]]; then properties[$uc_key$ID]=${alias_values[$fvalue]} else properties[$uc_key$ID]=$fvalue fi fi done typeset BOOT_ADAPTER_NODES=$(clodmget -q "network=$network and function=boot" -f nodename -n HACMPadapter) integer BOOT_ADAPTER_COUNT=$(print -- "$BOOT_ADAPTER_NODES" | wc -l) properties[BOOT_ADAPTERS$ID]=$BOOT_ADAPTER_COUNT integer UNIQUE_NW_NODES=$(print -- "$BOOT_ADAPTER_NODES" | sort -u | wc -l) properties[SINGLE_ADAPTER_NETWORK$ID]="false" if (( BOOT_ADAPTER_COUNT == UNIQUE_NW_NODES )) then properties[SINGLE_ADAPTER_NETWORK$ID]="true" fi unset BOOT_ADAPTER_NODES BOOT_ADAPTER_COUNT UNIQUE_NODES properties[SERVICE_ADAPTERS$ID]=$(clodmget -q "network=$network and function=shared" -f ip_label -n HACMPadapter | wc -l) properties[PERSISTENT_ADAPTERS$ID]=$(clodmget -q "network=$network and function=persistent" -f ip_label -n HACMPadapter | wc -l) #===================================================== # Service IP Resource Distribution Preference # AC == Anti-Collocation # C == Collocation # CPL == Collocation with Persistent Label # ACPL == Anti-Collocation with Persistent Label #===================================================== print "$0()[$LINENO]($SECONDS): clodmget -q \"network=$network AND function!=boot\" -n -f max_aliases HACMPadapter | sort -nu | tail -1" >>$CLMGR_TMPLOG # Always log commands DATA=$(clodmget -q "network=$network AND function != boot" -n -f max_aliases HACMPadapter) print "$0()[$LINENO]($SECONDS): clodmget RC: $?" >>$CLMGR_TMPLOG # Always log command result MA=$(print -- "$DATA" | sort -nu | tail -1) print "$0()[$LINENO]($SECONDS): Max Aliases == \"$MA\"" >>$CLMGR_TMPLOG typeset IPL="" if [[ -n $MA ]]; then print "$0()[$LINENO]($SECONDS): clodmget -q "max_aliases = $MA and network = $network" -n -f ip_label HACMPadapter" >>$CLMGR_TMPLOG IPL=$(clodmget -q "max_aliases = $MA and network = $network" -n -f ip_label HACMPadapter) print "$0()[$LINENO]($SECONDS): clodmget RC: $?; IPL == \"$IPL\"" >>$CLMGR_TMPLOG # Always log command result fi case $MA in 0|2) properties[RESOURCE_DIST_PREF$ID]="AC" ;; 1027) properties[RESOURCE_DIST_PREF$ID]="ACS" properties[SOURCE_IP$ID]=$IPL ;; 1) properties[RESOURCE_DIST_PREF$ID]="C" ;; 771) properties[RESOURCE_DIST_PREF$ID]="CS" properties[SOURCE_IP$ID]=$IPL ;; 259) properties[RESOURCE_DIST_PREF$ID]="CPL" ;; 515) properties[RESOURCE_DIST_PREF$ID]="ACPL" ;; 1539) properties[RESOURCE_DIST_PREF$ID]="ACPLS" properties[SOURCE_IP$ID]=$IPL ;; 1795) properties[RESOURCE_DIST_PREF$ID]="NOALI" ;; *) properties[RESOURCE_DIST_PREF$ID]="" ;; esac if [[ $CLMGR_GUI != *([[:space:]]) ]]; then typeset DONE= # Use this to eliminate duplicate service IP entries typeset -i INDEX=1 print "$0()[$LINENO]($SECONDS): cllsif -cSw" >>$CLMGR_TMPLOG # Always log commands DATA=$(cllsif -cSw) print "$0()[$LINENO]($SECONDS): cllsif RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" |\ while read LINE; do : Handle possible IPv6 address typeset IPv6= if [[ $LINE == *\[* ]]; then IPv6=${LINE##*\[} IPv6=${IPv6%%\]*} LINE=${LINE/\[$IPv6\]/[${IPv6//:/_}]} fi print -- "$LINE" | IFS=: read name type nw nettype attr node ipaddr haddr if gname netmask hb_addr site prefix family remainder : Handle possible IPv6 address ipaddr=${ipaddr//_/:} ipaddr=${ipaddr/\[/} ipaddr=${ipaddr/\]/} [[ -z $nw || $nw != $network || $DONE == *\ $name\ * ]] && continue [[ $type == "service" ]] && node= properties[INTERFACE$ID.$INDEX]=$name properties[INTERFACENAME$ID.$INDEX]=$if properties[IPADDR$ID.$INDEX]=$ipaddr properties[NODE$ID.$INDEX]=$node properties[SITENAME$ID.$INDEX]=$site properties[INTERFACETYPE$ID.$INDEX]=$type properties[HADDR$ID.$INDEX]=$haddr DONE="$DONE $name " (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) done fi done (( $rc == RC_UNKNOWN )) && rc=$RC_SUCCESS #========================================================== : 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_network_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_network_attributes =head1 SYNOPSIS clmgr query network [,,,...] clmgr -v query network NOTE: the aliases for "network" are "ne" and "nw". =head1 DESCRIPTION Retrieves the configuration data for one or more PowerHA networks. =head1 ARGUMENTS 1. network [REQUIRED] [string] The label of one or more PowerHA networks (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 =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 #==============================================================================