#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_efs_attributes.sh 1.3 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2011 
# 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 
# @(#)51	1.3  src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_efs_attributes.sh, hacmp.assist, 61haes_r714 6/25/12 13:56:04

# Start of POD-formatted documentation. Viewing suggestions:
#      perldoc <FILENAME>
#      pod2text -c <FILENAME>
#      pod2text -c --code <FILENAME>
#      pod2html <FILENAME>
function devDoc {
    : <<'=cut' >/dev/null 2>&1

=head1 NAME

 KLIB_HACMP_get_efs_attributes

=head1 VERSION

 Version Number:  1.3
 Last Extracted:  1/31/14 04:41:39
 Last Changed:    6/25/12 13:56:04

 Path, Component, Release(, Level):
 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_efs_attributes.sh, hacmp.assist, 61haes_r714

=head1 SYNOPSIS

 clmgr query efs <efs>[,<efs#2>,...]
 clmgr -v query efs

 NOTE: the alias for "efs" is "gp".

=head1 DESCRIPTION

Retrieves the information for one or more user efss.

=head1 ARGUMENTS

 1. efs [REQUIRED] [string]
    The label of one or more efss (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. 2005,2010
All Rights Reserved

=cut
} # End of POD-formatted documentation.


function KLIB_HACMP_get_efs_attributes {
    LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL"
    : version=1.3, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_get_efs_attributes.sh, hacmp.assist, 61haes_r714
    : INPUTS: $*

    typeset efs=${1//\"/}

    # Get the "properties" associative array reference, and initialize it
    if [[ -z $2 ]] || [[ -n $CLMGR_LOGGING && $2 == "|" ]]; then
        efs=
        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 -A list MODES
    MODES=(
        [1]="ldap"
        [2]="shared_fs"
    )
    typeset -i rc=$RC_UNKNOWN
    typeset DATA=

    CL=$LINENO KLIB_HACMP_is_known_efs
    if (( $? != RC_SUCCESS )); then
        CL=$LINENO cl_dspmsg -s 129 cspoc.cat 75 "EFS Kesytore is not configured.\n" 1>&2
        rc=$RC_NOT_FOUND
    fi

    #================================================================
    : Populate the return hash with the retrieved attributes/values
    #================================================================
    if (( $rc == RC_UNKNOWN )); then
        print -- "$0()[$LINENO]($SECONDS): $HAUTILS/clodmget -q \"group=EFSKeyStore AND name=mode\" -f value HACMPLDAP" >>$CLMGR_TMPLOG
        properties[MODE]=$($HAUTILS/clodmget -q "group=EFSKeyStore AND name=mode" -f value HACMPLDAP 2>>$CLMGR_TMPLOG)
        print -- "$0()[$LINENO]($SECONDS): clodmget RC: $?" >>$CLMGR_TMPLOG
        DATA=${properties[MODE]//\"/}
        [[ -n ${MODES[$DATA]} ]] && DATA=${MODES[$DATA]}
        properties[MODE]=$DATA

        print -- "$0()[$LINENO]($SECONDS): $HAUTILS/cllsres -c -s -g EFS_KeyStore | /usr/bin/tail -n 1 | /usr/bin/cut -d: -f2" >>$CLMGR_TMPLOG
        properties[VOLUME_GROUP]=$($HAUTILS/cllsres -c -s -g EFS_KeyStore | /usr/bin/tail -n 1 | /usr/bin/cut -d: -f2 2>>$CLMGR_TMPLOG)
        print -- "$0()[$LINENO]($SECONDS): cllsres RC: $?" >>$CLMGR_TMPLOG
        properties[VOLUME_GROUP]=${properties[VOLUME_GROUP]//\"/}

        print -- "$0()[$LINENO]($SECONDS): $HAUTILS/cllsres -c -s -g EFS_KeyStore | /usr/bin/tail -n 1 | /usr/bin/cut -d: -f15" >>$CLMGR_TMPLOG
        properties[SERVICE_IP]=$($HAUTILS/cllsres -c -s -g EFS_KeyStore | /usr/bin/tail -n 1 | /usr/bin/cut -d: -f15 2>>$CLMGR_TMPLOG)
        print -- "$0()[$LINENO]($SECONDS): cllsres RC: $?" >>$CLMGR_TMPLOG
        properties[SERVICE_IP]=${properties[SERVICE_IP]//\"/}

        rc=$RC_SUCCESS

        #==============================================================
        : 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[efs]}; do
            if [[ -z ${properties[$key]} ]]; then
                properties[$key]=""
            fi
        done
    fi

    log_return_msg "$rc" "$0()" "$LINENO"
    return $?
} # End of "KLIB_HACMP_get_efs_attributes()"
