#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2018,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_modify_service_ip.sh 1.4.1.1 # # 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_modify_service_ip.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_modify_service_ip # # Description: This is the main, FPATH function that is invoked by clmgr # to modify service IPs. It primarily uses the "clchnode" # utility to make all specified changes. # # Inputs: See the "devDoc()" function, below. # # 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, below, for the standard return # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_modify_service_ip { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_service_ip.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset service_ip=${2//\"/} shift; shift typeset new_name=${1//\"/} typeset new_network=${2//\"/} typeset netmask=${3//\"/} typeset prefix=${4//\"/} typeset hwaddr=${5//\"/} typeset site=${6//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then log_return_msg "$RC_MISSING_DEPENDENCY" "$0()" "$LINENO" return $? fi #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset -i i=0 typeset nodename= current_network= nim_name= #================================================================ : Assuming an object was specified, see if it is a known object #================================================================ if [[ $service_ip != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_service_ip "$service_ip" (( $? != RC_SUCCESS )) && rc=$RC_NOT_FOUND fi #================= : Validate input #================= if [[ -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 elif (( $rc == RC_NOT_FOUND )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$service_ip" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 156 "Available Service IPs:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_service_ip available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi # # make sure new label is resolvable before we go on # if [[ -n $new_name ]]; then typeset NAME="" IS="" ADDR="" REM="" LC_ALL=C host $new_name 2>/dev/null | read NAME IS ADDR REM if (( $? != 0 )) then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 767 '\nERROR: Address or name \"$new_name\" cannot be resolved. Check the input and name resolution then try again.\n' $new_name 1>&2 rc=$RC_NOT_FOUND fi fi #====================================================== : Make sure the customer provided something to change #====================================================== if [[ "$*" == *([[:space:]]) && \ " ${!_ENV_ARGS[*]} " != *\ SITE_IP\ * ]] then typeset ERRMSG=$(dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 '\nERROR: no valid modifications were specified for "%1$s".\n\n' "$service_ip") print -u2 "$ERRMSG" # This strips off one of the newlines unset ERRMSG rc=$RC_MISSING_INPUT class="service_ip" display_operation_syntax 0 2>&1 | sed "s//$service_ip/g" 1>&2 fi if [[ -n $new_network ]]; then CL=$LINENO KLIB_HACMP_is_known_network "$new_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' "$new_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 [[ $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 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 (( $rc == RC_UNKNOWN )) && [[ -n $netmask || -n $prefix ]]; then typeset ifName="" ifType="" network="" rest="" DATA="" print "$0()[$LINENO]($SECONDS): cllsif -cS" >>$CLMGR_TMPLOG # Always log commands DATA=$(cllsif -cS) integer cmd_rc=$? print "$0()[$LINENO]($SECONDS): cllsif RC: $cmd_rc" >>$CLMGR_TMPLOG print -- "$DATA" |\ while IFS=: read ifName ifType network rest; do [[ $ifName == $service_ip ]] && break done print "$0()[$LINENO]($SECONDS): clodmget -n -q name=$network -f net_family HACMPnetwork" >>$CLMGR_TMPLOG typeset NET_FAMILY=$(clodmget -n -q name=$network -f net_family HACMPnetwork) print "$0()[$LINENO]($SECONDS): clodmget RC: $? (NET_FAMILY=$NET_FAMILY)" >>$CLMGR_TMPLOG print "$0()[$LINENO]($SECONDS): cllsif -J \\\\\| -Sn $service_ip 2>/dev/null | cut -d\\\\\| -f 15" >>$CLMGR_TMPLOG typeset AF=$(cllsif -J \| -Sn $service_ip 2>/dev/null | cut -d\| -f 15) print "$0()[$LINENO]($SECONDS): clodmget RC: $? (AF=$AF)" >>$CLMGR_TMPLOG if [[ -z $AF || $AF != AF_INET* ]]; then # # address/label is not yet defined in the cluster - make sure # it is at least 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 # AF="AF_INET6" if [[ $NAME == +([0-9])\.+([0-9])\.+([0-9])\.+([0-9]) || $ADDR == +([0-9])\.+([0-9])\.+([0-9])\.+([0-9])?(,) ]] then AF="AF_INET" fi fi fi if [[ -n $netmask || -n $prefix ]]; then if [[ $AF == "AF_INET" && $NET_FAMILY == 2 ]]; then : The address, $service_ip, is IPv4 if [[ $prefix != *([[:space:]]) ]]; then netmask=$prefix prefix="" fi elif [[ $AF == "AF_INET6" && $NET_FAMILY == 1 ]]; then : The address, $service_ip, is IPv6 if [[ $netmask != *([[:space:]]) ]]; then prefix=$netmask netmask="" fi elif [[ $AF == "AF_INET" && $NET_FAMILY == 1 || \ $AF == "AF_INET6" && $NET_FAMILY == 2 ]] then #==================================================== : The network and address are of the same type. : Netmask/Prefix is not needed, and cannot be used. #==================================================== typeset TYPE="IPv4" [[ $NET_FAMILY == 2 ]] && TYPE="IPv6" cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 271 'The specified address, "%1$s", is of the same type (%2$s) as the specified network, "%3$s". So the netmask/prefix information specified for "%1$s" is not needed, and will instead be taken from "%3$s".\n' "$service_ip" "$TYPE" "$network" netmask="" prefix="" fi elif [[ -z $netmask && -z $prefix ]] && \ [[ $AF == "AF_INET" && $NET_FAMILY == 2 || \ $AF == "AF_INET6" && $NET_FAMILY == 1 ]] then typeset ADDR_TYPE="IPv4" [[ $AF == "AF_INET6" ]] && ADDR_TYPE="IPv6" typeset NET_TYPE="IPv4" [[ $NET_FAMILY == 2 ]] && 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 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 #============================================================== : Modify the service IP if no input errors have been detected #============================================================== if (( $rc == RC_UNKNOWN )); then typeset netarg="" if [[ -n $netmask ]]; then netarg="$netmask" elif [[ -n $prefix ]]; then netarg="$prefix" fi #===================================================== : Need to retrieve existing data for this service IP #===================================================== print "$0()[$LINENO]($SECONDS): odmget -q \"ip_label=$service_ip\" HACMPadapter" >>$CLMGR_TMPLOG # Always log commands odmget -q "ip_label=$service_ip" HACMPadapter |\ while IFS='=' read name value; do name=$(echo $name) value=${value//\"/} [[ $name == "nodename" ]] && nodename=$(echo $value) [[ $name == "network" ]] && current_network=$(echo $value) done eval $(clodmget -q ip_label=$service_ip HACMPadapter | tr ':' '\n') if [[ $new_name == *([[:space:]]) ]]; then new_name=$service_ip # The name was not changed fi if [[ $new_network == *([[:space:]]) ]]; then new_network=$current_network fi print "$0()[$LINENO]($SECONDS): clodmget -q name=$network -f nimname HACMPnetwork" >>$CLMGR_TMPLOG # Always log commands nim_name=$(clodmget -q name=$network -f nimname HACMPnetwork) print "$0()[$LINENO]($SECONDS): clodmget RC: $?; nim_name == \"$nim_name\"" >>$CLMGR_TMPLOG # Always log command result print "$0()[$LINENO]($SECONDS): clchnode -T service ${nodename:+-n $nodename} -a ${service_ip}:${new_name}:${nim_name//\\\"/}:${new_network}::service::${hwaddr}:${netarg}::${site}:" >>$CLMGR_TMPLOG # Always log commands clchnode -T service ${nodename:+-n $nodename} \ -a ${service_ip}:${new_name}:${nim_name//\"/}:${new_network}::service::${hwaddr}:${netarg}::${site}: rc=$? print "$0()[$LINENO]($SECONDS): clchnode RC: $rc" >>$CLMGR_TMPLOG # Always log command result (( $rc != RC_SUCCESS )) && rc=$RC_ERROR #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then [[ -n $new_name ]] && name=$new_name if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_service_ip_attributes "$name" 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_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' \ "modify service_ip -h" "SERVICE IP/LABEL:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_modify_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_modify_service_ip =head1 SYNOPSIS clmgr modify service_ip \ [ NAME= ] \ [ NETWORK= ] \ [ PREFIX= ] \ [ HWADDR= ] \ [ SITE= ] NOTE: the alias for "service_ip" is "si". =head1 DESCRIPTION Attempts to modify the specified service IP to conform to the provided specifications. =head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the modified 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 modified. 3. new_name [OPTIONAL] [string] The new IP address or lable that is to take the place of the specified service IP. 4. new_network [OPTIONAL] [string] The label of a new network bind this address within. 5. netmask [OPTIONAL] [string] A netmask to use with the service IP. 6. prefix [OPTIONAL] [string] A prefix length to use with the service IP. 7. hwaddr [OPTIONAL] [string] The hardware address to apply. 8. site [OPTIONAL] [string] The label of the site to use this service IP within. =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 #==============================================================================