#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_move_resourcegroup.sh 1.10.1.2 # # 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_move_resourcegroup.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_move_resourcegroup # # Description: This is the main, FPATH function that is invoked by clmgr # to move resource groups from node-to-node, or site-to-site. # It primarily uses the "clRGmove" utility to make all # specified moves. # # 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_move_resourcegroup { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_move_resourcegroup.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset rgs=${1//\"/} typeset node=${2//\"/} typeset site=${3//\"/} typeset -l state=${4//\"/} typeset -l secondary=${5//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset target="" stateOpt="" isSec="false" rg="" integer rc=$RC_UNKNOWN i=0 typeset DependentRG="" IndependentRG="" result="" rgs=${rgs#+([[:space:]])} rgs=${rgs%+([[:space:]])} rgs=${rgs//,/ } #========================================================================== : Verify that each specified object exists before attempting the operation #========================================================================== if [[ $rgs != *([[:space:]]) ]]; then for rg in $rgs; do CL=$LINENO KLIB_HACMP_is_known_rg "$rg" >/dev/null 2>&1 if (( $? != RC_SUCCESS )); then dspmsg -s $CLVT_SET $CLVT_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$rg" 1>&2 rc=$RC_NOT_FOUND fi done fi #================================================================ : 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 $rgs ]]; then dspmsg -s $CLVT_SET $CLVT_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 $CLVT_SET $CLVT_MSGS 154 "Available Resource Groups:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_resourcegroups available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" elif [[ -n $node && -n $site ]]; then dspmsg -s $CLVT_SET $CLVT_MSGS 36 '\nERROR: conflicting options were provided,\n "%1$s" versus "%2$s".\n\n' NODE SITE 1>&2 rc=$RC_INCORRECT_INPUT elif [[ -z $node && -z $site ]]; then dspmsg -s $CLVT_SET $CLVT_MSGS 408 '\nERROR: either "%1$s" or "%2$s" must be specified.\n\n' NODE SITE 1>&2 rc=$RC_MISSING_INPUT else if [[ -n $state ]]; then case $state in @(on|u)*) stateOpt="-u" ;; @(off|d)*) stateOpt="-d" ;; ?) dspmsg -s $CLVT_SET $CLVT_MSGS 110 '\nERROR: invalid value specified for "%1$s": "%2$s"\n\n' "STATE" "$state" 1>&2 rc=$RC_INCORRECT_INPUT ;; esac fi [[ -n $secondary && $secondary == @(t|y)* ]] && isSec="true" fi #======================================================= : Verify if user passed any dependent RGs as arguments #======================================================= for rg in $rgs do print "$0()[$LINENO]($SECONDS): clodmget -q \"group_name = $rg\" HACMPrg_loc_dependency" >>$CLMGR_TMPLOG result=$(clodmget -q "group_name = $rg" HACMPrg_loc_dependency) print "$0()[$LINENO]($SECONDS): clodmget ($rg + HACMPrg_loc_dependency): \"$result\"" >>$CLMGR_TMPLOG if [[ -z $result ]]; then print "$0()[$LINENO]($SECONDS): clodmget -q \"group_parent = $rg\" HACMPrgdependency" >>$CLMGR_TMPLOG result=$(clodmget -q "group_parent = $rg" HACMPrgdependency) print "$0()[$LINENO]($SECONDS): clodmget ($rg + parent + HACMPrgdependency): \"$result\"" >>$CLMGR_TMPLOG fi if [[ -z $result ]]; then print "$0()[$LINENO]($SECONDS): clodmget -q \"group_child = $rg\" HACMPrgdependency" >>$CLMGR_TMPLOG result=$(clodmget -q "group_child = $rg" HACMPrgdependency) print "$0()[$LINENO]($SECONDS): clodmget ($rg + child + HACMPrgdependency): \"$result\"" >>$CLMGR_TMPLOG fi if [[ -n $result ]] then : Create a a list of the specified resource groups that are : involved in dependencies with other resource groups DependentRG="$DependentRG $rg" else : Create a a list of the specified resource groups that are not : involved in any dependencies with other resource groups IndependentRG="$IndependentRG $rg" fi done #====================================================================== : Make sure that all specified dependent RGs are involved in the same : dependency. Moving multiple dependencies in one operation is not : supported. #====================================================================== if [[ -n $DependentRG ]] then CL=$LINENO KLIB_HACMP_list_dependencies deplist ( for (( i=0; i<${#deplist[*]}; i++ )) do [[ ${deplist[$i]} == *\(@(ACQUIRE|RELEASE)_* ]] && continue print -- "${deplist[$i]}" done ) >$TMPDIR/clmgr.KHmrg.$$ typeset DEPENDENCIES=$(cat $TMPDIR/clmgr.KHmrg.$$) rm -f $TMPDIR/clmgr.KHmrg.$$ integer DEPCNT=$(print -- "$DEPENDENCIES" | cut -d" " -f1 | egrep ${DependentRG// / -we } | wc -l) if (( DEPCNT > 1 )); then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1123 "\nWARNING: A resource group movement has been requested that affects resource groups involved in more than one dependency. \nIt is not recommended to move resource groups with multiple dependencies in a single operation. \nThe sequence of resource group movement should be carefully considered. \nProceeding with resource group movement.\n\n" 1>&2 print -- "$DEPENDENCIES" | egrep ${DependentRG// / -we } | sed "s/^/$TAB/g" >&2 print -u2 else cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1113 "\nThere is only one dependency involved in this resource group movement, as required:\n\n" result=$(print -- "$DEPENDENCIES" | cut -d" " -f1 | egrep ${DependentRG// / -we }) print -n "\t" print -- "$DEPENDENCIES" | grep -w "^$result" print fi unset DEPENDENCIES DEPCNT fi if [[ -n $DependentRG ]] then # Remove leading, trailing space and change space with comma for DependentRG DependentRG=${DependentRG#+([[:space:]])} DependentRG=${DependentRG%+([[:space:]])} DependentRG=${DependentRG// /,} fi if [[ -n $IndependentRG ]] then # Remove leading, trailing space for IndependentRG string IndependentRG=${IndependentRG#+([[:space:]])} IndependentRG=${IndependentRG%+([[:space:]])} fi #================================================================= : Move the resource groups if no input errors have been detected #================================================================= if (( $rc == RC_UNKNOWN )); then #======================================================================== : Move any specified dependent RGs together, if any. It is the : responsibility of the : customer to pass proper RGs in this case. As multiple RGs are moved : together, it is expected that all RGs are in same state. Please refer : to the clRGmove man pages for more details. #======================================================================== if [[ -n $DependentRG ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 197 '\nYou have specified multiple dependent groups \n"%1$s" to be moved.\n\ No checking of the current state or location will be done, and the move request will be handled directly\n\ by the cluster manager. Any errors during processing of the move, or any conflicts in the specified\n\ move request may result in failure of the move request\n\n' "$DependentRG" if [[ -n $node ]] then # Move RGs print "$0()[$LINENO]($SECONDS): clRGmove -s \"$isSec\" -m -i -g \"$DependentRG\" -n \"$node\"" >>$CLMGR_TMPLOG # Always log commands VERBOSE_LOGGING="" clRGmove -s "$isSec" -m -i -g "$DependentRG" -n "$node" rc=$? print "$0()[$LINENO]($SECONDS): clRGmove RC: $rc" >>$CLMGR_TMPLOG fi if [[ -n $site ]] then # Move RGs print "$0()[$LINENO]($SECONDS): clRGmove -s \"$isSec\" -x -i -g \"$DependentRG\" -n \"$site\"" >>$CLMGR_TMPLOG # Always log commands VERBOSE_LOGGING="" clRGmove -s "$isSec" -x -i -g "$DependentRG" -n "$site" rc=$? print "$0()[$LINENO]($SECONDS): clRGmove RC: $rc" >>$CLMGR_TMPLOG fi #================================================================ : Processing of dependent RGs is complete. Now filter out these : RGs from the main RG list and process only the remaining, : independent RGs. #================================================================ rgs=$IndependentRG fi #================================================= : Move any specified independent resource groups #================================================= if [[ -n $IndependentRG ]] then for rg in $rgs; do #============================================== : Get the current state of the resource group #============================================== typeset CSTATE= RG_NAME="" RG_STATE="" RG_NODE="" REST="" typeset -i RG_ONLINE=0 clRGinfo -c $rg |\ while IFS=: read RG_NAME RG_STATE RG_NODE REST; do if [[ $RG_STATE == ONLINE ]]; then RG_ONLINE=1 break fi done typeset SITE_NODES="" typeset -A siteAttrs if [[ -n $site ]]; then CL=$LINENO KLIB_HACMP_get_site_attributes $site siteAttrs SITE_NODES=" ${siteAttrs[NODES]//,/ } " fi if (( RG_ONLINE )); then : If a different node/site is specified, move $rg if [[ -n $node && $RG_NODE == $node || \ -n $site && $SITE_NODES == *\ $RG_NODE\ * ]] then : No need to move $rg. It is already in the desired location. dspmsg -s $CLMGR_SET $CLMGR_MSGS 1468 "\nWARNING: Resource group %1\$s is already online on the node %2\$s,\n hence no resource group movement is performed.\n" "$rg" "$node" elif [[ -n $node ]]; then print "$0()[$LINENO]($SECONDS): clRGmove -s \"$isSec\" -m -i -g \"$rg\" -n \"$node\"" >>$CLMGR_TMPLOG # Always log commands VERBOSE_LOGGING="" clRGmove -s "$isSec" -m -i -g "$rg" -n "$node" rc=$? print "$0()[$LINENO]($SECONDS): clRGmove RC: $rc" >>$CLMGR_TMPLOG elif [[ -n $site ]]; then print "$0()[$LINENO]($SECONDS): clRGmove -s \"$isSec\" -x -i -g \"$rg\" -n \"$site\"" >>$CLMGR_TMPLOG # Always log commands VERBOSE_LOGGING="" clRGmove -s "$isSec" -x -i -g "$rg" -n "$site" rc=$? print "$0()[$LINENO]($SECONDS): clRGmove RC: $rc" >>$CLMGR_TMPLOG fi if (( rc == 0 )); then if [[ $state == @(of|d)* ]]; then : Bringing $rg offline CL=$LINENO KLIB_HACMP_offline_resourcegroup "$rg" rc=$? else : $rg is already online rc=$RC_SUCCESS fi fi else # The resource group is currently offline : $rg is offline, so no move is needed. if [[ $state == @(on|u)* ]]; then if [[ -n $node ]]; then : Bringing $rg online on $node CL=$LINENO KLIB_HACMP_online_resourcegroup "$rg" "$node" else # site node=$(CL=$LINENO trim $SITE_NODES) node=${node%% *} : Bringing $rg online on $node, from site $site CL=$LINENO KLIB_HACMP_online_resourcegroup "$rg" "$node" fi rc=$? else : $rg is already offline rc=$RC_SUCCESS fi fi done fi fi #======================================================================= : If a user input error was detected, provide some helpful suggestions #======================================================================= if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \ [[ $CLVT_GUI == *([[:space:]]) ]] then cl_dspmsg -s $CLVT_SET $CLVT_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' \ "move resource_group -h" "RESOURCE GROUP:" "$CLVT_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_move_resourcegroup()" #============================================================================ # # 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_move_resourcegroup =head1 VERSION Version Number: 1.10.1.1 Last Extracted: 6/10/16 01:45:18 Last Changed: 6/8/16 01:12:29 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_move_resourcegroup.sh, hacmp.assist, 61haes_r721 =head1 SYNOPSIS clmgr move resource_group [,,,...] \ {SITE|NODE}= \ [ STATE={online|offline} ] \ [ SECONDARY={false|true} ] NOTE: the "SECONDARY" attribute defaults to "false". NOTE: the alias for "resource_group" is "rg". =head1 DESCRIPTION Attempts to move the specified resource group(s) from their current nodes or site to the specified new node or site. =head1 ARGUMENTS 1. rgs [REQUIRED] [string] One or more resource groups that are to be moved. 2. node [REQUIRED] [string] The name of the node to which the resource group(s) are to be moved. Must not be specified in conjunction with a site! 3. site [REQUIRED] [string] The name of the site to which the resource group(s) are to be moved. Must not be specified in conjunction with a node! 4. state [OPTIONAL] [string] The desired final state of the resource group after it has been moved: {online|offline} 5. secondary [OPTIONAL] [string] A Boolean-line indicator of whether or not the resource group(s) to be moved are primary or secondary instances. If no sites are in use, this attribute is not needed. =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: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================