#!/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_r714 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_storage_system.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
#
# @(#)  5f56dbd 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_storage_system.sh, 726, 2147A_aha726, Mar 08 2021 04:44 PM
 

# 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_is_known_storage_system

=head1 SYNOPSIS

KLIB_HACMP_is_known_storage_system

=head1 DESCRIPTION

Determines if the specified storage system
is configured within the cluster.

=head1 ARGUMENTS

 1. storage_system [REQUIRED] [string]
    The name of the storage system to search for on this node.

 2. TYPE [OPTIONAL] [reference]
    A string reference which can be used to return the discovered
    type of the specified storage system.

=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_is_known_storage_system {
    LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL"
    : version=@(#)  5f56dbd 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_storage_system.sh, 726, 2147A_aha726, Mar 08 2021 04:44 PM
    : INPUTS: $*

    typeset storage_system=${1//\"/}
    [[ -n $2 ]] && typeset -n TYPE=${2//\"/}
    TYPE=""
    [[ -n $3 ]] && typeset -n BACKUP_PROFILE=${3//\"/}

    [[ $CLMGR_LOGGING == 'med' ]] && set +x  # Only trace param values

    #===================================
    : Declare and initialize variables
    #===================================
    typeset -i rc=$RC_UNKNOWN
    typeset -A list
    typeset LINE="" name="" rest=""

    #=================
    : Validate input
    #=================
    if [[ -z $storage_system ]]; then
        /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2
        rc=$RC_MISSING_INPUT

    else
        if [[ -n $BACKUP_PROFILE ]]; then
            # Check Storage System exist in backup management XML file
            output=$(LANG=C cl_cbm_list_storage_profile "$storage_system" 2>>$CLMGR_TMPLOG)
            if [[ -n $output ]]; then
                rc=$RC_SUCCESS
            fi
            storage_type=$(echo "$output" | grep -w "Storage_type" | cut -f 2 -d '=')
            storage_type=${storage_type// /} # removes space
            TYPE=$storage_type
            BACKUP_PROFILE="Enable"
        else    
            isEnterprise
            if (( $? == 1 ));then
                print -- "$0()[$LINENO]($SECONDS): $HAXDWIZ/clxd_list_ss_director -d\"|\" -h $storage_system" >>$CLMGR_TMPLOG  # Always log commands
                $HAXDWIZ/clxd_list_ss_director -d"|" -h $storage_system 2>>$CLMGR_TMPLOG |\
                while read LINE; do
                    if [[ -n $LINE ]]; then
                        print -- "$LINE" | IFS=\| read name TYPE rest

                        if [[ $name == $storage_system ]]; then
                            rc=$RC_SUCCESS
                            break
                        else
                            TYPE=""
                        fi
                    fi
                done
            fi
        fi

        (( $rc != RC_SUCCESS )) && rc=$RC_ERROR
        print "$0()[$LINENO]($SECONDS): odmget RC: $rc" >>$CLMGR_TMPLOG  # Always log command result
    fi

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