#!/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_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_add_service_ip.sh 1.16.1.1 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2006,2015 # 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_service_ip.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_add_service_ip # # Description: This is the main, FPATH function that is invoked by clmgr # to add a service IP to the cluster configuration. # # Inputs: See the "devDoc()" function, below. # # Outputs: If the first argument is provided, it is established as # a reference, and all properties about the provided disk # are stored inside of it. Other than that, the only output # is any error messages that might occur. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function, below, for the standard return # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_add_service_ip { trap 'on_exit_add_service_ip' EXIT . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_add_service_ip.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset service_ip=${2//\"/} typeset network=${3//\"/} typeset netmask=${4//\"/} #optional typeset prefix=${5//\"/} #optional typeset hwaddr=${6//\"/} #optional typeset site=${7//\"/} #optional [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== rc=$RC_UNKNOWN # Declare globally, so it is visible in the exit function typeset -i i=0 typeset NET_FAMILY="UNKNOWN" typeset ADDR_FAMILY="UNKNOWN" typeset ODM_MASK="" #================================================================ : 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 $service_ip ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT else CL=$LINENO KLIB_HACMP_is_known_service_ip $service_ip if (( $? == RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 229 '\nERROR: the specified object already exists: "%1$s"\n\n' "$service_ip" 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 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 "" 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 [[ -n $netmask && -n $prefix ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 36 '\nERROR: conflicting options were provided,\n "%1$s" versus "%2$s".\n\n' NETMASK PREFIX 1>&2 rc=$RC_INCORRECT_INPUT fi #==================================================================== : If the specified address and the targeted network are of the same : type, no netmask/prefix is needed. If they differ, then a netmask : or prefix is *mandatory*. In the latter case, make an effort to : infer the intentions of the customer, in the case where a typo : has occurred, such as using PREFIX instead of NETMASK. #==================================================================== if [[ -n $service_ip ]]; then # : find the family of the underlying network # print "$0()[$LINENO]($SECONDS): clodmget -n -q name=$network -f net_family HACMPnetwork" >>$CLMGR_TMPLOG if [[ $(clodmget -n -q name=$network -f net_family HACMPnetwork) == 1 ]] then NET_FAMILY="AF_INET" else NET_FAMILY="AF_INET6" fi ODM_MASK=$(clodmget -n -q name=$network -f netmask HACMPnetwork) print "$0()[$LINENO]($SECONDS): Network $network is $NET_FAMILY, netmask/prefix is $ODM_MASK" >>$CLMGR_TMPLOG # # make sure label is resolvable before we go on # typeset NAME="" IS="" ADDR="" REM="" LC_ALL=C host $service_ip | read NAME IS ADDR REM if (( $? != 0 )) then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 767 '\nERROR: Address or name \"$service_ip\" cannot be resolved. Check the input and name resolution then try again.\n' $service_ip 1>&2 rc=$RC_NOT_FOUND else # # determine family based on general format # ADDR_FAMILY="AF_INET6" if [[ $ADDR == +([0-9])\.+([0-9])\.+([0-9])\.+([0-9])?(,) ]] then ADDR_FAMILY="AF_INET" fi fi if [[ -n $netmask || -n $prefix ]]; then if [[ $ADDR_FAMILY == "AF_INET" && $NET_FAMILY == "AF_INET6" ]]; then : The address, $service_ip, is IPv4 if [[ $prefix != *([[:space:]]) ]]; then netmask=$prefix prefix="" fi elif [[ $ADDR_FAMILY == "AF_INET6" && $NET_FAMILY == "AF_INET" ]]; then : The address, $service_ip, is IPv6 if [[ $netmask != *([[:space:]]) ]]; then prefix=$netmask netmask="" fi elif [[ ($ADDR_FAMILY == "AF_INET" && $NET_FAMILY == "AF_INET") || \ ($ADDR_FAMILY == "AF_INET6" && $NET_FAMILY == "AF_INET6") ]] then #==================================================== : The network and address are of the same type so we : silently ignore any Netmask/Prefix provided, as : long as it is the same as whats already in use. : But if they do give us a different netmask, let them : know that their input is being ignored. #==================================================== if [[ (-n $prefix && $prefix != $ODM_MASK) || (-n $netmask && $netmask != $ODM_MASK) ]] then typeset TYPE="IPv4" [[ $ADDR_FAMILY == "AF_INET6" ]] && TYPE="IPv6" cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 779 'The specified address "%1$s", is of the same family (%2$s) as network "%3$s". The specified netmask/prefix will not be used, and will instead be taken from "%3$s".\n' "$service_ip" "$TYPE" "$network" fi netmask="" prefix="" fi elif [[ -z $netmask && -z $prefix ]] && \ [[ $ADDR_FAMILY == "AF_INET" && $NET_FAMILY == "AF_INET6" || \ $ADDR_FAMILY == "AF_INET6" && $NET_FAMILY == "AF_INET" ]] then typeset ADDR_TYPE="IPv4" [[ $ADDR_FAMILY == "AF_INET6" ]] && ADDR_TYPE="IPv6" typeset NET_TYPE="IPv4" [[ $NET_FAMILY == "AF_INET6" ]] && NET_TYPE="IPv6" if [[ $ADDR_TYPE == "IPv6" ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 272 '\nERROR: the specified address, "%1$s", is of a different type (%2$s) than the specified network, "%3$s" (%4$s). A prefix length must be provided.\n\n' "$service_ip" "$ADDR_TYPE" "$network" "$NET_TYPE" 1>&2 else cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 273 '\nERROR: the specified address, "%1$s", is of a different type (%2$s) than the specified network, "%3$s" (%4$s). A netmask must be provided.\n\n' "$service_ip" "$ADDR_TYPE" "$network" "$NET_TYPE" 1>&2 fi rc=$RC_MISSING_INPUT fi fi # : Validate the netmask and or prefix length # if [[ $prefix != *([[:space:]]) ]] && \ ( [[ $prefix != +([[:digit:]]) ]] || (( prefix < 1 || prefix > 128 )) ) then dspmsg -s $CLMGR_SET $CLMGR_MSGS 113 '\nERROR: an invalid IPv6 prefix length was specified: %1$s\n\n' "$prefix" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "1 .. 128" 1>&2 rc=$RC_INCORRECT_INPUT fi if [[ -n $netmask ]]; then typeset nodots=${netmask//\./} if (( ${#netmask} - ${#nodots} != 3 )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 115 '\nERROR: an invalid IPv4 netmask was specified: %1$s\n\n' "$netmask" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "<###.###.###.###>; \"###\" must be in the range 0 .. 255." 1>&2 rc=$RC_INCORRECT_INPUT else typeset value=$netmask for (( i=0; i<4; i++ )); do typeset octet=${value%%.*} value=${value#*.} if [[ $octet == *([[:space:]]) || \ $octet != +([[:digit:]]) ]] || \ (( octet < 0 || octet > 255 )) then dspmsg -s $CLMGR_SET $CLMGR_MSGS 115 '\nERROR: an invalid IPv4 netmask was specified: %1$s\n\n' "$netmask" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "<###.###.###.###>; \"###\" must be in the range 0 .. 255." 1>&2 rc=$RC_INCORRECT_INPUT break fi done fi fi # # Validate the (optional) site input # if [[ $site != *([[:space:]]) ]]; then if [[ $CLUSTER_TYPE != @(SC|LC) ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 267 '\nERROR: the "%1$s" option is not appropriate for a cluster type of "%2$s".\n\n' SITE "$CLUSTER_TYPE" 1>&2 rc=$RC_INCORRECT_INPUT elif [[ $site != "ignore" ]]; then CL=$LINENO KLIB_HACMP_is_known_site "$site" >/dev/null if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$site" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 157 "Available Sites:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_sites available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" rc=$RC_NOT_FOUND fi fi fi #============================================================== : Create the service IP if no input errors have been detected #============================================================== if (( $rc == RC_UNKNOWN )); then if [[ -n $netmask ]]; then typeset nodots=${netmask//\./} if (( ${#netmask} - ${#nodots} != 3 )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 115 '\nERROR: an invalid IPv4 netmask was specified: %1$s\n\n' "$netmask" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "<###.###.###.###>; \"###\" must be in the range 0 .. 255." 1>&2 rc=$RC_INCORRECT_INPUT else typeset value=$netmask for (( i=0; i<4; i++ )); do typeset octet=${value%%.*} value=${value#*.} if [[ $octet == *([[:space:]]) || \ $octet != +([[:digit:]]) ]] || \ (( octet < 0 || octet > 255 )) then dspmsg -s $CLMGR_SET $CLMGR_MSGS 115 '\nERROR: an invalid IPv4 netmask was specified: %1$s\n\n' "$netmask" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "<###.###.###.###>; \"###\" must be in the range 0 .. 255." 1>&2 rc=$RC_INCORRECT_INPUT break fi done fi fi if (( $rc == RC_UNKNOWN )); then typeset netarg="" if [[ -n $netmask ]]; then netarg="-P $netmask" elif [[ -n $prefix ]]; then netarg="-P $prefix" fi typeset zVal="ignore" if [[ $site != *([[:space:]]) ]]; then zVal=$site fi print "$0()[$LINENO]($SECONDS): claddnode -T 'service' -B $service_ip -w $network -z $zVal $netarg >$TMPDIR/clmgr.KHasi.tmp.$$" >>$CLMGR_TMPLOG # Always log commands claddnode -T 'service' \ -B $service_ip \ -w $network \ -z $zVal $netarg >$TMPDIR/clmgr.KHasi.tmp.$$ 2>&1 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' "$service_ip" 1>&2 if [[ -f $TMPDIR/clmgr.KHasi.tmp.$$ ]]; then cat $TMPDIR/clmgr.KHasi.tmp.$$ 1>&2 print -u2 rm -f $TMPDIR/clmgr.KHasi.tmp.$$ fi elif [[ -n $hwaddr ]]; then typeset modProps CL=$LINENO KLIB_HACMP_modify_service_ip modProps $service_ip "" "" "" "" "$hwaddr" "" rc=$? if (( $rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 201 '\nERROR: failed to create "%1$s".\n\n' "$service_ip" 1>&2 cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 781 'Running the delete code to attempt to ensure that no partial instance of "%1$s" remains...\n' "$service_ip" 1>&2 : Clean up any partially created/configured node CL=$LINENO KLIB_HACMP_delete_service_ip "$service_ip" >/dev/null 2>&1 fi 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_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' \ "add service_ip -h" "SERVICE IP/LABEL:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_add_service_ip()" #============================================================================ # # Name: on_exit_add_service_ip # # Description: Signal handler for KLIB_HACMP_add_service_ip - if a # signal is caught, cat the content of the intermediate # work file which has any stdout/stderr from the claddnode # commmand # # Inputs: none # # Outputs: any output or errors from claddnode # # Returns: none # #============================================================================ function on_exit_add_service_ip { if (( $rc == RC_UNKNOWN )); then if [[ -f $TMPDIR/clmgr.KHasi.tmp.$$ ]]; then /usr/bin/cat $TMPDIR/clmgr.KHasi.tmp.$$ 1>&2 /usr/bin/rm -f $TMPDIR/clmgr.KHasi.tmp.$$ fi print exit $RC_ERROR fi } # End of "on_exit_add_service_ip()" #============================================================================ # # 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_service_ip =head1 SYNOPSIS clmgr add service_ip \ NETWORK= \ [ {NETMASK=<255.255.255.0 | PREFIX=1..128} ] \ [ SITE= ] NOTE: the alias for "service_ip" is "si". =head1 DESCRIPTION Attempts to create a service IP within the cluster configuration. head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the created object can be returned to the caller. 2. service_ip [REQUIRED] [string] The IP address or label of the service IP that is to be created. 3. network [REQUIRED] [string] The label of the network that this address will be bound to. 4. netmask [OPTIONAL] [string] An alternate netmask to use for the service IP (the netmask of the underlying network is used by default). 5. prefix [OPTIONAL] [string] An alternate prefix length to use for the service IP (the prefix of the underlying network is used by default). 6. site [OPTIONAL] [string] The name of the site to associate with this service label. =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 #==============================================================================