#!/bin/ksh93
# @(#)  7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_nova.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2017,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              

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


=head1 SYNOPSIS

KLIB_HACMP_is_known_nova

=head1 DESCRIPTION

 Determines if the specified NovaLink is configured within the cluster.

=head1 ARGUMENTS

 1. NovaLink [REQUIRED] [string]
 The name of the NovaLink to search for on this node. Either hostname
  or IP address for the NovaLink. IPv4 and IPv6 format address are supported.

=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 POD-formatted documentation.


function KLIB_HACMP_is_known_nova {
    LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL"
    : INPUTS: $*

    typeset -n novalabel=${1//\"/}

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

    #===================================
    : Declare and initialize variables
    #===================================
    typeset -i rc=$RC_UNKNOWN
    typeset -i found=0
    typeset -A list

    #=================
    : Validate input
    #=================
    if [[ -z $novalabel ]]; then
        /usr/bin/dspmsg -s $CLVT_SET $CLVT_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2
        rc=$RC_MISSING_INPUT
    else
        typeset NOVA="" rest=""
        #================================
        : Convert Host name/Ip to Name 
        #================================
        print -- "$0()[$LINENO]($SECONDS): LC_ALL=C host $novalabel" >>$CLMGR_TMPLOG # Always log commands
        NOVA=$(LC_ALL=C host $novalabel 2>/dev/null) 
        rc=$?
        print -- "$0()[$LINENO]($SECONDS): host $novalabel output=$NOVA rc=$rc">>$CLMGR_TMPLOG # Always log commands result
        if (( $rc == RC_SUCCESS )); then
            novalabel=${NOVA%% *}
        fi
        if [[ -n $novalabel ]]; then 
            typeset NOVA_PROPERTIES=
            print -- "$0()[$LINENO]($SECONDS): cllsnova -c -u $novalabel" >>$CLMGR_TMPLOG # Always log commands
            NOVA_PROPERTIES=$(cllsnova -c -u $novalabel)
	    rc=$?
            print -- "$0()[$LINENO]($SECONDS): cllsnova -c -u $novalabel rc=$rc" >>$CLMGR_TMPLOG # Always log commands result
            if (( $rc == RC_SUCCESS )); then
                if [[ -n $(cllsnova -c -u $novalabel | grep -v "^#") ]]; then   
                    rc=$RC_SUCCESS
                fi
            fi
            (( $rc != RC_SUCCESS )) && rc=$RC_NOT_FOUND
        fi
    fi
    log_return_msg "$rc" "$0()" "$LINENO"
    return $?
} # End of "KLIB_HACMP_is_known_nova()"
