#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_mirror_group_attributes.sh 1.22 # # 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 # @(#)73 1.22 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_mirror_group_attributes.sh, hacmp.assist, 61haes_r720, 1525A_hacmp720 6/1/15 14:04:59 #============================================================================ # # Name: KLIB_HACMP_get_mirror_group_attributes # # Description: This is the main, FPATH function that is invoked by clmgr # to collect mirror group information. The clxd_list_mg_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_mirror_group_attributes { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=1.22, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_mirror_group_attributes.sh, hacmp.assist, 61haes_r720, 1525A_hacmp720 : INPUTS: $* typeset mirror_group=${1//\"/} # Get the "properties" associative array reference, and initialize it if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then mirror_group= typeset -n properties=$1 else typeset -n properties=$2 fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values CL=$LINENO isEnterprise if (( $? != 1 )); then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 184 "\nERROR: this operation requires IBM PowerHA SystemMirror for AIX Enterprise Edition.\n\n" 1>&2 log_return_msg "$RC_MISSING_DEPENDENCY" "$0()" "$LINENO" return $? fi #=================================== : Declare and initialize variables #=================================== for k in ${!properties[*]}; do unset properties[$k]; done typeset GROUPS= 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 #=================================================== : Check for any specified attribute=value groups. : 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 #======================================= : Make sure we have something to query #======================================= if [[ -n $mirror_group ]]; then [[ $mirror_group != *,* ]] && unset INDEX for mirror_group in ${mirror_group//,/ }; do CL=$LINENO KLIB_HACMP_is_known_mirror_group "$mirror_group" 2>/dev/null if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$mirror_group" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 167 "Available Mirror Groups:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_mirror_groups 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 GROUPS="$GROUPS $mirror_group" fi done elif (( CLMGR_VERBOSE || ${#queries[*]} > 0 )); then CL=$LINENO KLIB_HACMP_list_mirror_groups list for name in ${list[*]}; do name=${name##+([[:space:]])} name=${name%%+([[:space:]])} GROUPS="$GROUPS $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 GROUPS #================================================================ : Populate the return hash with the retrieved attributes/values #================================================================ for mirror_group in $GROUPS; do properties[NAME$INDEX]=$mirror_group print -- "$0()[$LINENO]($SECONDS): $HAXDWIZ/clxd_list_mg_director -d\"|\" $mirror_group | grep \"^$mirror_group|\"" >>$CLMGR_TMPLOG # Always log commands $HAXDWIZ/clxd_list_mg_director -d"|" $mirror_group | grep "^$mirror_group|" >$TMPDIR/clmgr.KHgmga.$$ cmd_rc=$? print "$0()[$LINENO]($SECONDS): clxd_list_mg_director RC: $cmd_rc" >>$CLMGR_TMPLOG # Always log command result if (( $cmd_rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 167 '\nERROR: the specified mirror_group, "%1$s", could not be found.\n\n' "$mirror_group" 1>&2 rc=$RC_NOT_FOUND break fi typeset -l MODE="" RECOVERY="" RESYNC="" CONSISTENT="" typeset -u MG_STATE="" typeset NAME="" MG_TYPE="" STORAGE_SYSTEMS="" VENDOR_ID="" typeset HORCM_INSTANCE="" HORCM_TIMEOUT="" PAIR_EVENT_TIMEOUT="" typeset ATTRIBUTES="" REM="" while IFS=\| read NAME MODE CONSISTENT RECOVERY VENDOR_ID \ STORAGE_SYSTEMS ATTRIBUTES HYPERSWAP_ENABLED \ MG_TYPE HYPERSWAP_PRIORITY UNPLANNED_HS_TIMEOUT \ VOLUME_GROUPS RAW_DISKS SYS_MG_NODE \ REPOSITORY_MG_SITES REPOSITORY_MG_HS_DISK \ REPOSITORY_MG_NONHS_DISK RESYNC MG_STATE \ HORCM_INSTANCE HORCM_TIMEOUT PAIR_EVENT_TIMEOUT do properties[NAME$INDEX]="$NAME" properties[STATE$INDEX]="$MG_STATE" MODE=${MODE/metro/sync} MODE=${MODE/global/async} properties[MODE$INDEX]="$MODE" [[ $RECOVERY == a* ]] && RECOVERY="automatic" properties[RECOVERY$INDEX]="$RECOVERY" [[ $RESYNC == a* ]] && RESYNC="automatic" properties[RESYNC$INDEX]="$RESYNC" properties[STORAGE_SYSTEMS$INDEX]="$STORAGE_SYSTEMS" properties[CONSISTENT$INDEX]="$CONSISTENT" properties[VENDOR_ID$INDEX]="$VENDOR_ID" properties[ATTRIBUTES$INDEX]="$ATTRIBUTES" case $MG_TYPE in # HyperSwap mirror groups @(U|u)*) properties[MG_TYPE$INDEX]=$(dspmsg -s 4 genxd.cat 56 "User") ;; @(S|s)*) properties[MG_TYPE$INDEX]=$(dspmsg -s 4 genxd.cat 57 "System") ;; @(R|r)*) properties[MG_TYPE$INDEX]=$(dspmsg -s 4 genxd.cat 58 "Repositories") ;; # EMC mirror groups @(C|c)*) properties[MG_TYPE$INDEX]="composite" ;; @(D|d)*) properties[MG_TYPE$INDEX]="device" ;; esac properties[HYPERSWAP_ENABLED$INDEX]="$HYPERSWAP_ENABLED" properties[HYPERSWAP_PRIORITY$INDEX]="$HYPERSWAP_PRIORITY" if [[ $UNPLANNED_HS_TIMEOUT == 0x* ]]; then UNPLANNED_HS_TIMEOUT=$(printf "%d" $UNPLANNED_HS_TIMEOUT) fi properties[UNPLANNED_HS_TIMEOUT$INDEX]="$UNPLANNED_HS_TIMEOUT" properties[VOLUME_GROUPS$INDEX]="$VOLUME_GROUPS" properties[RAW_DISKS$INDEX]="$RAW_DISKS" properties[SYS_MG_NODE$INDEX]="$SYS_MG_NODE" properties[REPOSITORY_MG_SITES$INDEX]="$REPOSITORY_MG_SITES" properties[REPOSITORY_MG_HS_DISK$INDEX]="$REPOSITORY_MG_HS_DISK" properties[REPOSITORY_MG_NONHS_DISK$INDEX]="${REPOSITORY_MG_NONHS_DISK%%:*}" properties[HORCM_INSTANCE$INDEX]="$HORCM_INSTANCE" properties[HORCM_TIMEOUT$INDEX]="$HORCM_TIMEOUT" properties[PAIR_EVENT_TIMEOUT$INDEX]="$PAIR_EVENT_TIMEOUT" done <$TMPDIR/clmgr.KHgmga.$$ rm -f $TMPDIR/clmgr.KHgmga.$$ typeset -A ssProps STORAGE_SYSTEMS=${properties[STORAGE_SYSTEMS$INDEX]//,/ } if [[ $STORAGE_SYSTEMS != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_get_storage_system_attributes "${STORAGE_SYSTEMS%% *}" ssProps properties[TYPE$INDEX]="${ssProps[TYPE]}" elif [[ ${properties[HORCM_INSTANCE$INDEX]} != *([[:space:]]) ]]; then properties[TYPE$INDEX]="hitachi" else properties[TYPE$INDEX]="emc" fi if [[ ${properties[MG_TYPE$INDEX]} == *([[:space:]]) ]]; then if [[ ${properties[TYPE$INDEX]} == "ds8k_inband_mm" ]]; then properties[MG_TYPE$INDEX]="user" elif [[ ${properties[TYPE$INDEX]} == "emc" ]]; then properties[MG_TYPE$INDEX]="composite" fi fi if [[ ${properties[TYPE$INDEX]} == "svc" ]]; then properties[MIRROR_PAIRS$INDEX]=${properties[ATTRIBUTES$INDEX]} properties[ATTRIBUTES$INDEX]="" fi properties[RESOURCE_GROUP$INDEX]=$(clodmget -n -q "value=${properties[NAME$INDEX]}" -f group HACMPresource) #============================================================== : 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[mirror_group]}; do if [[ -z ${properties[$key$INDEX]} ]]; then properties[$key$INDEX]="" fi done if [[ ${properties[TYPE$INDEX]} != "ds8k_inband_mm" ]]; then #============================================================ : Remove HyperSwap-only attributes if not HyperSwap storage #============================================================ for key in HYPERSWAP_ENABLED HYPERSWAP_PRIORITY \ UNPLANNED_HS_TIMEOUT VOLUME_GROUPS RAW_DISKS \ SYS_MG_NODE REPOSITORY_MG_SITES \ REPOSITORY_MG_HS_DISK REPOSITORY_MG_NONHS_DISK do unset properties[$key$INDEX] done elif [[ ${properties[MG_TYPE$INDEX]} == "user" ]]; then #======================================================= : Remove the attributes that do not apply to a USER MG #======================================================= for key in VENDOR_ID SYS_MG_NODE REPOSITORY_MG_SITES \ REPOSITORY_MG_HS_DISK REPOSITORY_MG_NONHS_DISK do unset properties[$key$INDEX] done elif [[ ${properties[MG_TYPE$INDEX]} == "system" ]]; then #========================================================= : Remove the attributes that do not apply to a SYSTEM MG #========================================================= for key in VENDOR_ID REPOSITORY_MG_SITES RECOVERY RESYNC \ REPOSITORY_MG_HS_DISK REPOSITORY_MG_NONHS_DISK do unset properties[$key$INDEX] done elif [[ ${properties[MG_TYPE$INDEX]} == "repository" ]]; then #============================================================= : Remove the attributes that do not apply to a REPOSITORY MG #============================================================= for key in VOLUME_GROUPS RAW_DISKS VENDOR_ID SYS_MG_NODE \ RECOVERY do unset properties[$key$INDEX] done fi if [[ ${properties[TYPE$INDEX]} != @(ds8k_inband_mm|emc) ]]; then unset properties[MG_TYPE$INDEX] fi if [[ ${properties[TYPE$INDEX]} != "svc" ]]; then unset properties[MIRROR_PAIRS$INDEX] else unset properties[VENDOR_ID$INDEX] fi if [[ ${properties[TYPE$INDEX]} == @(hitachi|svc) ]]; then unset properties[CONSISTENT$INDEX] fi if [[ ${properties[TYPE$INDEX]} != @(ds8k_*|svc|xiv_rm) ]]; then unset properties[STORAGE_SYSTEMS$INDEX] fi if [[ ${properties[TYPE$INDEX]} != "hitachi" ]]; then unset properties[HORCM_INSTANCE$INDEX] unset properties[HORCM_TIMEOUT$INDEX] unset properties[PAIR_EVENT_TIMEOUT$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_mirror_group_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_mirror_group_attributes =head1 VERSION Version Number: 1.22 Last Extracted: 6/16/15 17:51:07 Last Changed: 6/1/15 14:04:59 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_mirror_group_attributes.sh, hacmp.assist, 61haes_r720, 1525A_hacmp720 =head1 SYNOPSIS clmgr query mirror_group [,,...] clmgr -v query mirror_group NOTE: the alias for "mirror_group" is "mg". =head1 DESCRIPTION Retrieves the configuration data for one or more PowerHA SystemMirror mirror disk groups. =head1 ARGUMENTS 1. mirror_group [REQUIRED] [string] The label of one or more mirror groups (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. 2011,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 #==============================================================================