#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_persistent_ip.sh 1.5 # # 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 # @(#)00 1.5 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_persistent_ip.sh, hacmp.assist, 61haes_r720, 1543A_hacmp720 10/16/15 14:31:26 #============================================================================ # # Name: KLIB_HACMP_modify_persistent_ip # # Description: This is the main, FPATH function that is invoked by clmgr # to modify persistent IPs in the cluster configuration. # # 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_persistent_ip { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=1.5, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_persistent_ip.sh, hacmp.assist, 61haes_r720, 1543A_hacmp720 : INPUTS: $* typeset -n properties=$1 typeset persistent_ip=${2//\"/} shift; shift typeset new_name=${1//\"/} typeset new_network=${2//\"/} typeset prefix=${3//\"/} typeset netmask=${4//\"/} [[ $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 nodename= current_network= nettype= typeset -i i=0 #================================================================ : Assuming an object was specified, see if it is a known object #================================================================ if [[ $persistent_ip != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_persistent_ip "$persistent_ip" (( $? != RC_SUCCESS )) && rc=$RC_NOT_FOUND fi #================= : Validate input #================= if [[ -z $persistent_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' "$persistent_ip" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 152 "Available Persistent Node IPs:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_persistent_ip available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi if [[ "$*" == *([[:space:]]) ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 '\nERROR: no valid modifications were specified for "%1$s".\n\n' "$persistent_ip" 1>&2 log_return_msg "$RC_MISSING_INPUT" "$0()" "$LINENO" return $? 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 [[ -n $netmask && -n $prefix ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 36 '\nERROR: conflicting options were provided, "%1$s" versus "%2$s".\n\n' NETMASK PREFIX 1>&2 rc=$RC_INCORRECT_INPUT fi #================================================================= : Modify the persistent IP if no input errors have been detected #================================================================= if (( $rc == RC_UNKNOWN )); then #======================================================== : Need to retrieve existing data for this persistent IP #======================================================== print "$0()[$LINENO]($SECONDS): cllsif -pcS" >>$CLMGR_TMPLOG # Always log commands typeset DATA=$(cllsif -pcS) print "$0()[$LINENO]($SECONDS): cllsif RC: $?" >>$CLMGR_TMPLOG # Always log command result print -- "$DATA" |\ while read LINE; do : Handle possible IPv6 address typeset IPv6= if [[ $LINE == *\[* ]]; then IPv6=${LINE##*\[} IPv6=${IPv6%%\]*} LINE=${LINE/\[$IPv6\]/[${IPv6//:/_}]} fi print -- "$LINE" | IFS=: read name type current_network nettype attr nodename ipaddr rem : Handle possible IPv6 address ipaddr=${ipaddr//_/:} ipaddr=${ipaddr/\[/} ipaddr=${ipaddr/\]/} [[ $type != "persistent" ]] && continue if [[ $persistent_ip == @($name|$ipaddr) ]]; then break fi done [[ -n $netmask ]] && typeset save_nm=$netmask [[ -n $prefix ]] && typeset save_px=$prefix eval $(clodmget -q ip_label=$persistent_ip HACMPadapter | tr ':' '\n') [[ -n $save_nm ]] && netmask=$save_nm [[ -n $save_px ]] && prefix=$save_px if [[ $new_name == *([[:space:]]) ]]; then new_name=$persistent_ip # The name was not changed elif [[ $new_name == +([0-9])\.+([0-9])\.+([0-9])\.+([0-9]) ]]; then print "$0()[$LINENO]($SECONDS): The specified new label appears to be in address format: \"$new_name\"" >>$CLMGR_TMPLOG print "$0()[$LINENO]($SECONDS): Attempting to convert \"$new_name\" to a label." >>$CLMGR_TMPLOG typeset NAME="" IS="" ADDR="" REST="" print "$0()[$LINENO]($SECONDS): LC_ALL=C host \"$new_name\"" >>$CLMGR_TMPLOG LC_ALL=C host "$new_name" 2>>$CLMGR_TMPLOG | read NAME IS ADDR REST ADDR=${ADDR%,} if [[ $ADDR == $new_name ]]; then print "$0()[$LINENO]($SECONDS): \"$new_name\" was converted to \"$NAME\"." >>$CLMGR_TMPLOG new_name=$NAME if [[ $new_name == *\.* ]]; then print "$0()[$LINENO]($SECONDS): The specified new label appears to be in FQDN format: \"$new_name\"" >>$CLMGR_TMPLOG new_name=${new_name%%\.*} print "$0()[$LINENO]($SECONDS): Stripping off the domain results in a new label of \"$new_name\"." >>$CLMGR_TMPLOG fi else cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 9999 '\nERROR: the specified IP label, "%1$s", could not be resolved by the "host" command. Make sure that "%1$s" is valid, and that it is properly defined in /etc/hosts. If so, confirm that local name resolution is in effect by checking that "local" is the first "hosts" option in /etc/netsvc.conf.\n\n' "$new_name" 1>&2 rc=$RC_INCORRECT_INPUT fi elif [[ $new_name == *\.* ]]; then print "$0()[$LINENO]($SECONDS): The specified new label appears to be in FQDN format: \"$new_name\"" >>$CLMGR_TMPLOG new_name=${new_name%%\.*} print "$0()[$LINENO]($SECONDS): Stripping off the domain results in a new label of \"$new_name\"." >>$CLMGR_TMPLOG fi if [[ $new_network == *([[:space:]]) ]]; then new_network=$current_network fi print "$0()[$LINENO]($SECONDS): cl_harvestIP_scripts -u $persistent_ip | tail -1 | cut -d: -f4" >>$CLMGR_TMPLOG # Always log commands nettype=$(cl_harvestIP_scripts -u $persistent_ip) integer cmd_rc=$? (( cmd_rc != RC_SUCCESS )) && rc=$RC_ERROR nettype=$(print -- "$nettype" | tail -1 | cut -d: -f4) print "$0()[$LINENO]($SECONDS): cl_harvestIP_scripts RC: $cmd_rc (nettype == $nettype)" >>$CLMGR_TMPLOG # Always log command result typeset netarg=$prefix if [[ -n $netmask ]]; then netarg=$netmask fi if (( rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): clchnode -n $nodename -a ${persistent_ip}:${new_name}:${nettype}:${new_network}::persistent::${hwaddr}:${netarg}::${site}:" >>$CLMGR_TMPLOG # Always log commands clchnode -n $nodename \ -a ${persistent_ip}:${new_name}:${nettype}:${new_network}::persistent::${hwaddr}:${netarg}::${site}: rc=$? print "$0()[$LINENO]($SECONDS): clchnode RC: $rc" >>$CLMGR_TMPLOG # Always log command result (( $rc != RC_SUCCESS )) && rc=$RC_ERROR fi fi #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then [[ -n $new_name ]] && persistent_ip=$new_name if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_persistent_ip_attributes "$persistent_ip" 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_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 ext.\n\n' \ "modify persistent_ip -h" "PERSISTENT IP/LABEL:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_modify_persistent_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_persistent_ip =head1 VERSION Version Number: 1.5 Last Extracted: 10/20/15 18:14:19 Last Changed: 10/16/15 14:31:26 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_persistent_ip.sh, hacmp.assist, 61haes_r720, 1543A_hacmp720 =head1 SYNOPSIS clmgr modify persistent_ip \ [ NAME= ] \ [ NETWORK= ] \ [ {NETMASK=<###.###.###.###> | PREFIX=1..128} ] NOTE: the alias for "persistent_ip" is "pe". =head1 DESCRIPTION Attempts to modify the specified persistent 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. persistent_ip [REQUIRED] [string] The IP address or label of the persistent IP that is to be modified. 3. new_name [OPTIONAL] [string] A new address to apply for this persistent IP. 4. new_network [OPTIONAL] [string] The label of a new network that this address should be bound to. 5. prefix [OPTIONAL] [string] A new prefix length for this persistent IP. 6. netmask [OPTIONAL] [string] A new netmask for this persistent IP. =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 =head1 COPYRIGHT COPYRIGHT International Business Machines Corp. 2011,2015 All Rights Reserved =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: #==============================================================================