#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2018,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_storage_system_attributes.sh 1.12 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011,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 # # @(#) 5f56dbd 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_storage_system_attributes.sh, 726, 2147A_aha726, Mar 08 2021 04:44 PM #============================================================================ # # Name: KLIB_HACMP_get_storage_system_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect storage system information. The clxd_list_ss_director # 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_storage_system_attributes { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 5f56dbd 43haes/lib/ksh93/hacmp/KLIB_HACMP_get_storage_system_attributes.sh, 726, 2147A_aha726, Mar 08 2021 04:44 PM : INPUTS: $* typeset storage_system=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then storage_system= typeset -n properties=$1 shift else typeset -n properties=$2 shift shift fi typeset -i backup=0 if (( $# >= 1 )); then backup=${1//\"/} shift fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset SYSTEMS= typeset -A list typeset -i INDEX=0 rc=$RC_SUCCESS typeset key= typeset -i matches=0 typeset -u attr= uc_key= typeset -A queries typeset -i i=0 typeset name type vendor_id wwnn site agents attrs role partner svc_cluster_id rem #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then log_return_msg "$RC_MISSING_DEPENDENCY" "$0()" "$LINENO" return $? fi #=================================================== : 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 (( ! CLMGR_VERBOSE )) && \ [[ -z $storage_system && \ $CLMGR_ATTRS == "VENDOR_ID" && \ -n ${queries[TYPE]} ]] then #==================================================== : If the special case is detected where a vendor ID : listing is desired, just list them, and return. #==================================================== if [[ ${queries[TYPE]} != @(ds8k_gm|ds8k_inband_mm|xiv_rm) ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 472 '\nERROR: the specified storage technology, "%1$s", does not support vendor IDs in storage systems.\n\n' "${queries[TYPE]}" 1>&2 rc=$RC_INCORRECT_INPUT elif [[ ${queries[TYPE]} == "ds8k_inband_mm" && \ ${queries[AGENTS]} != *([[:space:]]) ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 473 '\nERROR: the specified storage technology, "%1$s", does not support storage agents.\n\n' "${queries[TYPE]}" 1>&2 rc=$RC_INCORRECT_INPUT else typeset aOpts="" if [[ ${queries[AGENTS]} != *([[:space:]]) ]]; then typeset agent="" for agent in ${queries[AGENTS]//,/ }; do aOpts="$aOpts -a $agent" done fi print -- "$0()[$LINENO]($SECONDS): $HAXDCLI/clxd_discover_ss \"${queries[TYPE]}\" -d\"|\"$aOpts" >>$CLMGR_TMPLOG # Always log commands LC_ALL=C LANG=C $HAXDCLI/clxd_discover_ss "${queries[TYPE]}" -d"|"$aOpts >$TMPDIR/clmgr.KHgssa.lsvid.$$ rc=$? if (( $rc == RC_SUCCESS )); then typeset ID="" REST="" while IFS="|" read ID REST; do [[ $ID == *\ * ]] && continue properties[VENDOR_ID$INDEX]=$ID (( INDEX++ )) done <$TMPDIR/clmgr.KHgssa.lsvid.$$ rm -f $TMPDIR/clmgr.KHgssa.lsvid.$$ : The following settings will force a simple display list export CLMGR_SUPPRESS=1 export CLMGR_COLON=1 fi fi log_return_msg "$rc" "$0()" "$LINENO" return $? fi #======================================= : Make sure we have something to query #======================================= if [[ -n $storage_system ]]; then [[ $storage_system != *,* ]] && unset INDEX typeset BACKUP_PROFILE="" for storage_system in ${storage_system//,/ }; do if (( $backup == 1 )); then BACKUP_PROFILE="Enable" fi CL=$LINENO KLIB_HACMP_is_known_storage_system "$storage_system" TYPE BACKUP_PROFILE 2>/dev/null if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$storage_system" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 164 "Available Storage Systems:\n\n" 1>&2 typeset available if [[ $BACKUP_PROFILE == "Enable" ]]; then CL=$LINENO KLIB_HACMP_list_storage_systems available BACKUP=1 else CL=$LINENO KLIB_HACMP_list_storage_systems list fi 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 SYSTEMS="$SYSTEMS $storage_system" fi done elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then if (( $backup == 1 )); then CL=$LINENO KLIB_HACMP_list_storage_systems list BACKUP=1 else CL=$LINENO KLIB_HACMP_list_storage_systems list fi for name in ${list[*]}; do name=${name##+([[:space:]])} name=${name%%+([[:space:]])} SYSTEMS="$SYSTEMS $name" 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 )) && unset SYSTEMS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for storage_system in $SYSTEMS; do properties[NAME$INDEX]=$storage_system backup_profile="Disable" if (( $backup == 1 )); then output=$(LANG=C cl_cbm_list_storage_profile "$storage_system" 2>>$CLMGR_TMPLOG ) cmd_rc=$? if (( $cmd_rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$storage_system" 1>&2 rc=$RC_NOT_FOUND break fi storage_name=$(echo "$output" | grep -w "Storage_name" | cut -f 2 -d '=') storage_name=${storage_name// /} # removes space storage_type=$(echo "$output" | grep -w "Storage_type" | cut -f 2 -d '=') storage_type=${storage_type// /} # removes space username=$(echo "$output" | grep -w "Username" | cut -f 2 -d '=') username=${username// /} # removes space ip_address=$(echo "$output" | grep -w "IP_address" | cut -f 2 -d '=') backup_profile="Enable" delim="|" print "$storage_name${delim}$storage_type${delim}${delim}${delim}${delim}${delim}$ip_address${delim}${delim}${delim}$username${delim}$backup_profile${delim}$svc_cluster_id" >$TMPDIR/clmgr.KHgssa.ss.$$ else CL=$LINENO isEnterprise if (( $? == 1 ));then print -- "$0()[$LINENO]($SECONDS): $HAXDWIZ/clxd_list_ss_director -d\"|\" -h -n $storage_system" >>$CLMGR_TMPLOG # Always log commands $HAXDWIZ/clxd_list_ss_director -d"|" -h -n $storage_system >$TMPDIR/clmgr.KHgssa.ss.$$ cmd_rc=$? print "$0()[$LINENO]($SECONDS): clxd_list_ss_director RC: $cmd_rc; OUTPUT == \"$OUTPUT\"" >>$CLMGR_TMPLOG # Always log command result fi if (( $cmd_rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$storage_system" 1>&2 rc=$RC_NOT_FOUND break fi fi while IFS=\| read name type vendor_id wwnn site agents attrs role partner username backup_profile svc_cluster_id rem; do [[ $name == *([[:space:]]) ]] && continue properties[NAME$INDEX]="$name" properties[TYPE$INDEX]=$type properties[VENDOR_ID$INDEX]=$vendor_id properties[WWNN$INDEX]=$wwnn properties[SITE$INDEX]=$site properties[AGENTS$INDEX]=$agents if [[ $type != "svc" ]]; then properties[ATTRIBUTES$INDEX]=$attrs else properties[ADDRESSES$INDEX]=$attrs properties[ROLE$INDEX]=$role properties[PARTNER$INDEX]=$partner properties[USER$INDEX]=$username properties[BACKUP_PROFILE$INDEX]=$backup_profile properties[SVC_CLUSTER_ID$INDEX]=$svc_cluster_id fi done <$TMPDIR/clmgr.KHgssa.ss.$$ rm -f $TMPDIR/clmgr.KHgssa.ss.$$ #============================================================== : 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[storage_system]}; do if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done #========================================================== : Hide outputs that are not relevant for the storage type #========================================================== if [[ ${properties[TYPE$INDEX]} != "svc" ]]; then unset properties[ADDRESSES$INDEX] unset properties[ROLE$INDEX] unset properties[PARTNER$INDEX] unset properties[USER$INDEX] unset properties[BACKUP_PROFILE$INDEX] unset properties[SVC_CLUSTER_ID$INDEX] fi if [[ ${properties[TYPE$INDEX]} != @(ds8k_gm|xiv)* ]]; then unset properties[AGENTS$INDEX] fi (( INDEX++ )) [[ $INDEX == *0 ]] && (( INDEX++ )) 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_storage_system_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_storage_system_attributes =head1 SYNOPSIS clmgr query storage_system [,,...] clmgr query storage_system [,,...] BACKUP=1 clmgr -v query storage_system clmgr -v query storage_system BACKUP=1 clmgr -a VENDOR_ID query storage_system \ TYPE=(ds8k_gm|ds8k_inband_mm|xiv_rm} NOTE: this form of query is for listing available vendor IDs. NOTE: the alias for "storage_system" is "sts". =head1 DESCRIPTION Retrieves the configuration data for one or more PowerHA SystemMirror storage systems. =head1 ARGUMENTS 1. storage_system [REQUIRED] [string] The label of one or more storage_systems (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 #==============================================================================