#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2019,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_add_interface.sh 1.7 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 1990,2010 # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_add_interface.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_add_interface # # Description: This is the main, FPATH function that is invoked by clmgr # to add a new interface to an existing network. # # 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_add_interface { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_add_interface.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset address=${2//\"/} shift; shift typeset type=${1//\"/} # Defaults to "ether" typeset network=${2//\"/} # optional typeset node=${3//\"/} # optional typeset nw_interface=${4//\"/} # optional [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset args= typeset -i rc=$RC_UNKNOWN typeset -u typeUC=$type #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY #================= : Validate input #================= elif [[ -z $address ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 202 "\nERROR: this operation requires an IP address or resolvable name.\n\n" 1>&2 rc=$RC_MISSING_INPUT else CL=$LINENO KLIB_HACMP_is_known_interface $address if (( $? == RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 229 "\nERROR: the specified object already exists: \"%1\$s\"\n\n" "$address" 1>&2 rc=$RC_INCORRECT_INPUT fi fi if [[ -z $network ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 101 "\nERROR: this operation requires the \"%1\$s\" attribute.\n\n" NETWORK 1>&2 rc=$RC_MISSING_INPUT else CL=$LINENO KLIB_HACMP_is_known_network "$network" >/dev/null 2>&1 if (( $? != RC_SUCCESS )); then rc=$RC_INCORRECT_INPUT dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 "\nERROR: \"%1\$s\" does not appear to exist!\n\n" "$network" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 150 "Available Networks:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_networks available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi fi if (( $rc == RC_UNKNOWN )); then if [[ -z $type ]]; then if [[ -n $network ]] then typeset -A nw_props CL=$LINENO KLIB_HACMP_get_network_attributes "$network" nw_props [[ -n ${nw_props[TYPE]} ]] && type=${nw_props[TYPE]} fi [[ -z $type ]] && type="ether" elif [[ $typeUC != @(E|XD_D|XD_I)* ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\".\n" TYPE "$type" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "ether, XD_data, XD_ip" 1>&2 rc=$RC_INCORRECT_INPUT fi [[ -z $node ]] && node="$LOCAL_NODE" if [[ -z $node ]]; then node="$(hostname)" node=${node%%.*} fi [[ -n $nw_interface ]] && nw_interface=" -I $nw_interface" if (( $rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): claddnode -a\"$address\":\"$type\":\"$network\"::: -n\"$node\"$nw_interface" >>$CLMGR_TMPLOG # Always log commands claddnode -a"$address":"$type":"$network"::: -n"$node"$nw_interface rc=$? print "$0()[$LINENO]($SECONDS): claddnode RC: $rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc != RC_SUCCESS )); then rc=$RC_ERROR dspmsg -s $CLMGR_SET $CLMGR_MSGS 201 "\nERROR: failed to create \"%1\$s\".\n\n" "$address" 1>&2 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_interface_attributes "$address" properties fi 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 \"man clmgr\"),\nsearching for \"%2\$s\" in the displayed text.\n\n" \ "add interface -h" "INTERFACE:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_add_interface()" #============================================================================ # # 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_add_interface =head1 SYNOPSIS clmgr add interface \ NETWORK= \ [ NODE= ] \ [ TYPE={ether|XD_data|XD_ip} ] \ [ INTERFACE= ] NOTE: the "interface" may be either an IP address or label NOTE: the "NODE" attribute defaults to the local node name. NOTE: the "TYPE" attribute defaults to "ether" NOTE: the "" might look like "en1", "en2", ... NOTE: the aliases for "interface" are "in" and "if". =head1 DESCRIPTION Attempts to create a new interface object within the cluster that conforms to the provided specifications. =head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the created object can be returned to the caller. 2. address [REQUIRED] [string] The address to use when creating the new interface. 3. type [OPTIONAL] [string] The type of interface being added, defaulting to "ether" (Ethernet) 4. network [REQUIRED] [string] The label of the network to add this interface to/within. 5. node [OPTIONAL] [string] The label of the node upon which the IP label/address will be bound. Defaults to the local node. 6. nw_interface [OPTIONAL] [string] The network interface associated with this interface (e.g. en1, en2, etcetera...). =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 "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 #==============================================================================