#!/bin/ksh93
# @(#)  7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_cluster_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                                                      
#                                                                              

#================================================
# The following, commented line enforces hmcing
# standards when this file is edited via vim.
#================================================
# vim:tabstop=4:shiftwidth=4:expandtab:smarttab
#================================================

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

=head1 NAME

 KLIB_HACMP_modify_cluster_nova

=head1 SYNOPSIS

 clmgr manage cluster nova \
             [ DEFAULT_NOVA_TIMEOUT=<MINUTES> ] \
             [ DEFAULT_NOVA_RETRY_COUNT=<INTEGER> ]\
             [ DEFAULT_NOVA_RETRY_DELAY=<SECONDS> ]\
             [ CONNECTION_TYPE={ssh} ]
 NOTE: the alias for "cluster" is "cl".

=head1 DESCRIPTION

Attempts to modify the cluster NovaLink configuration.

=head1 ARGUMENTS

 1. properties [REQUIRED] [hash ref]
    An associative array within which data about the
    modified object can be returned to the caller.

 2. DEFAULT_NOVA_TIMEOUT [OPTIONAL] [integer]
    The default timeout for DLPAR acquisition/release NovaLink operations.
    This value is expressed in minutes.
    For memory release operations, 1 minute per GBytes is added to this value.
    The timeout value can also be set on each NovaLink separately.

 3. DEFAULT_NOVA_RETRY_COUNT [OPTIONAL] [integer]
    The default value for the number of retries on NovaLink operations.
    The NovaLink operation which timeouts will be retried this number of times.
    The retry count value can also be set on each NovaLink separately.

 4. DEFAULT_NOVA_RETRY_DELAY [OPTIONAL] [integer]
    The default value for duration of delay between two retries
     set on NovaLink operations.
    This value is expressed in seconds.
    The NovaLink operation which gets times out,then will be retried 'default_nova_retry_count' number of times, with 'default_nova_retry_delay' seconds between each retry.
    The retry delay value can also be set on each NovaLink separately. 

  5. CONNECTION_TYPE [OPTIONAL] [string] 
    The connection type is used to for passwordless  
    connection to NovaLink to perform DLPAR,EPCoD and OnOff CoD operations. 
    Default value for this parameter is SSH.


=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_modify_cluster_nova {
    LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL"
    : INPUTS: $*

    typeset -n properties=$1
    shift

    typeset user_input=$*
    typeset default_timeout=${1//\"/}
    typeset default_retry_count=${2//\"/}
    typeset default_retry_delay=${3//\"/}
    typeset connection_type=${4//\"/}

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

    #===================================
    : Declare and initialize variables
    #===================================
    typeset -i rc=$RC_UNKNOWN
    typeset -A clattrs

    CL=$LINENO KLIB_HACMP_get_cluster_attributes clattrs

    #================================================================
    : Check for a defined cluster. No need to continue without one.
    #================================================================
    if [[ -z ${clattrs[CLUSTER_NAME]} ]]; then
        /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 35 "\nERROR: no cluster is defined yet.\n\n" 1>&2
        rc=$RC_MISSING_DEPENDENCY

    #=================
    : Validate input
    #=================
    elif [[ $user_input == *([[:space:]]) ]] ; then
        /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 "\nERROR: no valid modifications were specified for \"%1\$s\".\n\n" "$(cllsclstr -cS | /usr/bin/cut -d: -f2)" 1>&2
        rc=$RC_MISSING_INPUT
    fi

    if (( $rc == RC_UNKNOWN )); then
        if [[ -n $default_timeout && $default_timeout != +([[:digit:]]) ]] ; then
            /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 111 "\nERROR: \"%1\$s\" requires a positive, integer value.\n\n" DEFAULT_NOVA_TIMEOUT 1>&2
            rc=$RC_INCORRECT_INPUT
        fi

        if [[ -n $default_retry_count && $default_retry_count != +([[:digit:]]) ]] ; then
            /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 111 "\nERROR: \"%1\$s\" requires a positive, integer value.\n\n" DEFAULT_NOVA_RETRY_COUNT 1>&2
            rc=$RC_INCORRECT_INPUT
        fi

        if [[ -n $default_retry_delay && $default_retry_delay != +([[:digit:]]) ]] ; then
            /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 111 "\nERROR: \"%1\$s\" requires a positive, integer value.\n\n" DEFAULT_NOVA_RETRY_DELAY 1>&2
            rc=$RC_INCORRECT_INPUT
        fi

        if [[ $connection_type != *([[:space:]]) ]]; then
            CL=$LINENO verify_in_set CONNECTION_TYPE "$connection_type" "ssh" connection_type
            (( $? != RC_SUCCESS )) && rc=$RC_INCORRECT_INPUT
        fi
    fi

    
    #=================================
    # Tune the cluster, if requested
    #=================================
    if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then
        if [[ -n $default_timeout ]]; then
            #================================================
            : Setting default_timeout to "$default_timeout"
            #================================================
            print "HACMPnovaparam:
default_timeout=$default_timeout" | /usr/bin/odmchange -o HACMPnovaparam
            typeset VAL=$(clodmget -f default_timeout HACMPnovaparam)
            [[ $VAL == $default_timeout ]] && rc=$RC_SUCCESS || rc=$RC_ERROR
        fi
    fi

    if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then
        if [[ -n $default_retry_count ]]; then
            #================================================
            : Setting default_retry_count to "$default_retry_count"
            #================================================
            print "HACMPnovaparam:
default_retry_count=$default_retry_count" | /usr/bin/odmchange -o HACMPnovaparam
            typeset VAL=$(clodmget -f default_retry_count HACMPnovaparam)
            [[ $VAL == $default_retry_count ]] && rc=$RC_SUCCESS || rc=$RC_ERROR
        fi
    fi

    if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then
        if [[ -n $default_retry_delay ]]; then
            #================================================
            : Setting default_retry_delay to "$default_retry_delay"
            #================================================
            print "HACMPnovaparam:
default_retry_delay=$default_retry_delay" | /usr/bin/odmchange -o HACMPnovaparam
            typeset VAL=$(clodmget -f default_retry_delay HACMPnovaparam)
            [[ $VAL == $default_retry_delay ]] && rc=$RC_SUCCESS || rc=$RC_ERROR
        fi
    fi

    
    if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then
        if [[ -n $connection_type ]]; then
            connectiontype=0    #setting the connection type to ssh and is only valid.
        else
            connectiontype=0    #setting the connection type to ssh and is only valid.
        fi 
            #==============================================================
            : Setting connection_type to "$connectiontype" 0=ssh 
            #==============================================================
            print "HACMPnovaparam:
connection_type=$connectiontype" | /usr/bin/odmchange -o HACMPnovaparam
            typeset VAL=$(clodmget -f connection_type HACMPnovaparam)
            [[ $VAL == $connectiontype ]] && rc=$RC_SUCCESS || rc=$RC_ERROR
    fi

    if (( rc == RC_SUCCESS )); then
        #===========================================================
        # Set the "handle" attribute in the HACMPcluster class
        # to zero to indicate that an unsynced change exists in
        # the cluster configuration. 
        #===========================================================
        if [[ -n $default_timeout || 
                    -n $default_retry_delay || 
                    -n $default_retry_delay || 
                    -n $connection_type ]]; then
            print "\
HACMPcluster:
\thandle=0" | /usr/bin/odmchange -o HACMPcluster
        fi
    fi

    #===========================================================
    : If output from this operation was requested, retrieve it
    #===========================================================
    if (( $rc == RC_SUCCESS )); then
        if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then
            CL=$LINENO KLIB_HACMP_get_cluster_attributes properties
        fi
    fi

    #=======================================================================
    : If a user input error was detected, provide some helpful suggestions
    #=======================================================================
    if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \
       [[ $CLMGR_GUI == *([[:space:]]) ]]
    then
        CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 104 "For more information about available options and syntax, try\n\"$HAUTILS/clmgr %1\$s\". As an\nalternative, if the PowerHA SystemMirror man pages have been installed, invoke\n\"$HAUTILS/clmgr -hv\" (or \"/usr/bin/man clmgr\"),\nsearching for \"%2\$s\" in the displayed text.\n\n" \
        "manage cluster -h" "CLUSTER:" "$CLMGR_PROGNAME" 1>&2
    fi

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