#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2017,2020,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_site.sh 1.18.1.8 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2010,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_modify_site.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_modify_site # # Description: This is the main, FPATH function that is invoked by clmgr # to modify sites. It primarily uses the "clchgsite" utility # to make all specified changes to the given site. # # 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_site { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_site.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset -n properties=$1 typeset site=${2//\"/} typeset new_site=${3//\"/} typeset nodes=${4//\"/} nodes=${nodes//,/ } typeset site_ip=${5//\"/} typeset recovery_priority=${6//\"/} typeset repositories=${7//\"/} repositories=${repositories//,/ } typeset hmcs=${8//\"/} hmcs=${hmcs//,/ } typeset new_site_=$new_site typeset old_site_=$site [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #================================================================= : Remove the required inputs from the argument list. This makes : it easier to check for the specification of any modifications. #================================================================= shift; shift #================================================================ : 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 -A site_data typeset -u upper_key= typeset sOpt= key= typeset -i i=0 #================================================================ : Assuming an object was specified, see if it is a known object #================================================================ if [[ $site != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_site "$site" >/dev/null 2>&1 (( $? != RC_SUCCESS )) && rc=$RC_NOT_FOUND fi #================= : Validate input #================= if [[ -z $site ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT else if (( $rc == RC_NOT_FOUND )); 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 "" fi if [[ -n $recovery_priority ]]; then if [[ $recovery_priority == @(M|m)* ]]; then recovery_priority=0 # Manual recovery elif [[ $recovery_priority != @(0|1|2) ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 '\nERROR: invalid value specified for "%1$s": "%2$s".\n' RECOVERY_PRIORITY "$recovery_priority" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "MANUAL, 1, 2" 1>&2 rc=$RC_INCORRECT_INPUT fi fi if [[ -n $site_ip ]]; then : Verify we have a valid multicast IP format CL=$LINENO verify_is_multicast_address $site_ip (( $? != RC_SUCCESS )) && rc=RC_INCORRECT_INPUT fi #=================================== : Get the current site information #=================================== CL=$LINENO KLIB_HACMP_get_site_attributes "$site" site_data if [[ -n $new_site && -n "${new_site//[a-zA-Z0-9_]/}" ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 105 '\nERROR: one or more invalid characters were detected in "%1$s" ("%2$s").\n\nValid characters include letters, numbers, and underscores only.\n\n' "$new_site" "${new_site//[a-zA-Z0-9_]/}" 1>&2 rc=$RC_INCORRECT_INPUT fi #====================================================== : Make sure the customer provided something to change #====================================================== if [[ "$*" == *([[:space:]]) && \ " ${!_ENV_ARGS[*]} " != *\ SITE_IP\ * ]] then dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 '\nERROR: no valid modifications were specified for "%1$s".\n\n' "$site" 1>&2 rc=$RC_MISSING_INPUT fi #============================================================== : If nodes were specified, verify that they are known nodes. : NODES_OF_SITE is set to either the nodes received or to the : already set nodes of this site. #============================================================== typeset NODES_OF_SITE="" if [[ $nodes != *([[:space:]]) ]]; then typeset -i all_nodes_found=1 for node in ${nodes//,/ }; do CL=$LINENO KLIB_HACMP_is_known_node "$node" >/dev/null 2>&1 if (( $? != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$node" 1>&2 rc=$RC_INCORRECT_INPUT all_nodes_found=0 fi done if (( ! all_nodes_found )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 151 "Available Nodes:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_nodes available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi NODES_OF_SITE=$nodes else print "$0()[$LINENO]($SECONDS): clodmget -q \"name=$site\" -n -f nodelist HACMPsite" >>$CLMGR_TMPLOG # Always log commands NODES_OF_SITE=$(clodmget -q "name=$site" -n -f nodelist HACMPsite) print "$0()[$LINENO]($SECONDS): clodmget RC: $?; $site nodes == $NODES_OF_SITE" >>$CLMGR_TMPLOG fi if [[ -n $repositories && -z $NODES_OF_SITE ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1004 '\nERROR: repositories may only be specified if nodes are specified.\n\n' 1>&2 rc=$RC_INCORRECT_INPUT fi if [[ -n $repositories && $CLUSTER_TYPE != "LC" ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 437 '\nERROR: repositories may only be specified per site in a linked cluster.\n\n' 1>&2 rc=$RC_INCORRECT_INPUT fi #=========================================== : Check the number of backup repositories. #=========================================== integer NB_NEW_BACKUP_REPOS=$(print $repositories | LC_ALL=C wc -w) [[ -z $NB_NEW_BACKUP_REPOS ]] && NB_NEW_BACKUP_REPOS=0 || (( NB_NEW_BACKUP_REPOS-=1)) if (( $NB_NEW_BACKUP_REPOS > $MAX_NB_OF_BACKUP_REPOSITORIES )); then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1001 '\nERROR: a linked cluster cannot get more than "%1$s" backup repositories (there were "%2$s" backup repositories, and you want to add "%3$s" backup repositories).\n\n' "$MAX_NB_OF_BACKUP_REPOSITORIES" "0" "${NB_NEW_BACKUP_REPOS}" 1>&2 rc=$RC_INCORRECT_INPUT fi integer error_found=1 if [[ -n $hmcs ]]; then #================================================ : Verify that the list of hmcs passed in is the : exact list of hmcs already set on this site #================================================ typeset HMCLABELS="" print "$0()[$LINENO]($SECONDS): cllssite -S $site " >>$CLMGR_TMPLOG # Always log commands HMCLABELS=$(cllssite -S $site | sort -u) print "$0()[$LINENO]($SECONDS): cllssite -S $site; HMCs == ${HMCLABELS//+([[:space:]])/, }" >>$CLMGR_TMPLOG # Always log command result typeset hmcs_sorted=$(print -- "$hmcs" | tr ' ' '\n' | sort -u) [[ $HMCLABELS == $hmcs_sorted ]] && error_found=0 || error_found=1 #===================================================== : If verification step fails, then reject the change #===================================================== if (( $error_found == 1 )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 '\nERROR: invalid value specified for "%1$s": "%2$s".\n' HMCS "$hmcs" 1>&2 dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 'Valid values: %1$s\n\n' "${HMCLABELS//+([[:space:]])/, }" 1>&2 rc=$RC_INCORRECT_INPUT fi fi #================================================ : Configure the non-quoted command-line options #================================================ [[ -n $new_site ]] && sOpt="-s $new_site" [[ -n $recovery_priority ]] && POpt=" -P $recovery_priority" [[ -n $site_ip ]] && iOpt=" -i $site_ip" if [[ -z $nodes ]]; then : clchgsite requires nodes, so get the existing nodes nodes=$(clodmget -n -q "name=$site" -f nodelist HACMPsite) fi #======================================================== : Modify the site if no input errors have been detected # (as indicated by $rc still equal to RC_UNKNOWN). #======================================================== #============================================================= : Since the nodelists need to be quoted, and we want to : avoid using an eval, it is necessary to do separate : invocations of clchgsite here for each possible situation. #============================================================= if (( $rc == RC_UNKNOWN )); then if [[ -n $nodes ]]; then print "$0()[$LINENO]($SECONDS): clchgsite -p \"$site\" -n \"$nodes\" $sOpt$POpt$iOpt" >>$CLMGR_TMPLOG # Always log commands clchgsite -p "$site" -n "$nodes" $sOpt$POpt$iOpt else print "$0()[$LINENO]($SECONDS): clchgsite -p \"$site\" $sOpt$POpt$iOpt" >>$CLMGR_TMPLOG # Always log commands clchgsite -p "$site" $sOpt$POpt$iOpt fi rc=$? print "$0()[$LINENO]($SECONDS): clchgsite RC: $rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc != RC_SUCCESS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 400 '\nERROR: failed to modify "%1$s".\n\n' "$site" 1>&2 rc=$RC_ERROR fi fi #=========================================================== : if any repos mg and storage system exists with modified : site name, then change the odm #=========================================================== if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then if [[ -n $old_site_ ]]; then if [[ -n $new_site_ ]]; then is_clxd=$($HAXDCLI/clxd_list_mg -d:|tail +2 2>/dev/null) if [[ -n $is_clxd ]]; then print "HACMPxd_storage_system:\nxd_storage_system_site_affiliation=$new_site_" |\ odmchange -o HACMPxd_storage_system -q "xd_storage_system_site_affiliation=$old_site_" 2>/dev/null rc=$? cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 773 '\nModiying site with name "%1$s" in storage system completed with RC = "%2$s".\n\n' "$old_site_" "$rc" if (( $rc == 0 )); then print "HACMPxd_ext_attr:\nvalue=$new_site_" |\ odmchange -o HACMPxd_ext_attr -q "field_type=site and value=$old_site_" 2>/dev/null rc=$? cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 774 '\nModifying site with name "%1$s" in repository mirror group completed with RC = "%2$s".\n\n' "$old_site_" "$rc" fi if (( $rc == RC_SUCCESS )); then $HAXDCLI/clxd_refresh rc=$? fi (( $rc != RC_SUCCESS )) && rc=$RC_ERROR fi fi fi #===================================== # Modify repositories, if applicable #===================================== if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )); then if [[ -n $repositories ]]; then if (( ! incluster )); then typeset -A arprops CL=$LINENO KLIB_HACMP_add_repository arprops "$repositories" "$site" rc=$? elif [[ ${repositories//,/} != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_replace_repository "${repositories%% *}" "$site" rc=$? fi fi fi fi #=============================================================== : If verification step for hmcs is ok, then perform the change #=============================================================== if (( $rc == RC_UNKNOWN || $rc == RC_SUCCESS )) && \ (( $error_found == 0 )) then hmcs=${hmcs// /,} print "$0()[$LINENO]($SECONDS): clchgsite -p $site -H $hmcs " >>$CLMGR_TMPLOG # Always log commands clchgsite -p $site -H "$hmcs" rc=$? print "$0()[$LINENO]($SECONDS): clchgsite -p $site -H $hmcs rc=$rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc != RC_SUCCESS )); then rc=$RC_ERROR fi fi #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then [[ -n $new_site ]] && site=$new_site if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_site_attributes "$site" 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 site -h" "SITE:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_modify_site()" #============================================================================ # # 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_site =head1 VERSION Version Number: 1.18.1.8 Last Extracted: 10/15/15 19:21:05 Last Changed: 10/10/15 14:12:41 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_site.sh, hacmp.assist, 61haes_r720, 1542B_hacmp720 =head1 SYNOPSIS clmgr modify site \ [ NAME= ] \ [ NODES=[,,...] ] \ [ SITE_IP= ] \ [ RECOVERY_PRIORITY={MANUAL|1|2} ] \ [ REPOSITORIES=[,,...] ] \ [ HMCS=[,,...] ] NOTE: "SITE_IP" may only be used with a cluster type of "LC" ("Linked Clusters"). NOTE: "REPOSITORIES" may only be used with a cluster type of "LC". No more than MAX_NB_OF_BACKUP_REPOSITORIES backup repository disks may be defined per site of a "LC" cluster. =head1 DESCRIPTION Attempts to modify the specified site to conform 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. site [REQUIRED] [string] The label of the site that is to be modified. 3. new_site [OPTIONAL] [string] The new label to attempt to apply to the specified site. 4. nodes [OPTIONAL] [string] A list of nodes for the specified site. Thist list will completely replace the current list. 5. site_ip [OPTIONAL] [string] The multicast IP address to use for CAA communication within the CAA cluster for the site. 6. recovery_priority [OPTIONAL] [string] If the sites become sundered, when the communication problem is corrected, this setting dicates how CAA will know which site should be the main/recovery site. A numeric priority is assigned to each site. By default, though, the priority is set to zero, and the site with the largest number of active nodes is recovered. In the case of a tie (same number of active nodes), then the site with the lowest node ID "wins". 7. repositories [OPTIONAL] [string] One or more disks that will be added as repository disks within the cluster. First disk is the active repository, and following ones are backup repositories. Nor more than MAX_NB_OF_BACKUP_REPOSITORIES backup repositories are accepted per site. 8. hmcs [OPTIONAL] [string] At least two hmcs. Use this option to set the precedence order of the hmcs to be used by the site. You cannot add nor remove any hmc using this option, you simply can change the precedence order of them. =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. 2010,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 #==============================================================================