#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r721 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_delete_repository.sh 1.12.1.2 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2012,2016 # 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 # @(#)14 1.12.1.2 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_delete_repository.sh, hacmp.assist, 61haes_r721, 1638B_hacmp721 9/20/16 04:19:18 #============================================================================ # # Name: KLIB_HACMP_delete_repository # # Description: This is the main, FPATH function that is invoked by clmgr # to remove a repository disk from the cluster configuration. # Note that once a cluster has been fully formed, meaning a # synchronization has been done and the CAA cluster exists, # it will no longer be possible to remove the active/primary # repository disk(s). # # Inputs: See the "devDoc()" function, below. # # Outputs: None. # # 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_delete_repository { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=1.12.1.2, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_delete_repository.sh, hacmp.assist, 61haes_r721, 1638B_hacmp721 : INPUTS: $* typeset repositories=${1//\"/} repositories=${repositories//,/ } typeset site=${2//\"/} typeset node=${3//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== integer rc=$RC_UNKNOWN i=0 ACTIVE_REPOS=0 typeset repository= KNOWN_REPOSITORIES= JUNK= DEVNAME= PVID= typeset -A NODE_MAP #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then rc=$RC_MISSING_DEPENDENCY else CL=$LINENO KLIB_HACMP_list_repositories KNOWN_REPOSITORIES NODE_MAP #================= : Validate input #================= if [[ -z $repositories ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT else typeset -u uctext=$repositories if [[ $uctext == "ALL" ]]; then if [[ -n $site ]]; then for repository in ${!NODE_MAP[*]} do if [[ ${NODE_MAP[$repository]} != *\($site\) ]] then unset NODE_MAP[$repository] fi done fi repositories=${!NODE_MAP[*]} if (( ${#NODE_MAP[*]} == 0 )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 332 "Warning: there are no repositories to delete.\n" rc=$RC_SUCCESS fi fi fi fi #============================================================== : Delete the repository if no input errors have been detected #============================================================== if (( $rc == RC_UNKNOWN )); then for repository in $repositories; do repository=${repository#_} typeset ORIGINAL_REPOS=$repository #======================================================== : Attempt to improve the accuracy of ambiguous queries. : If there is exactly one match, use the PVID from that. #======================================================== typeset -i COUNT=0 typeset FOUND=-1 for (( i=0; i<${#KNOWN_REPOSITORIES[*]}; i++ )); do print -- "${KNOWN_REPOSITORIES[$i]}" |\ grep -qw $repository if (( $? == RC_SUCCESS )); then (( COUNT++ )) FOUND=$i fi done if (( COUNT == 1 )) && [[ -n ${KNOWN_REPOSITORIES[$FOUND]#* } ]] then repository=${KNOWN_REPOSITORIES[$FOUND]#* } repository=${repository#\(} repository=${repository%\)} fi typeset SITE="" DISK_DATA="" integer cmd_rc=$RC_UNKNOWN if [[ $CLUSTER_TYPE == "LC" ]]; then if [[ -n $site ]]; then CL=$LINENO REFNODE=$node KLIB_HACMP_is_known_repository "$repository" "$site" DISK_DATA 2>/dev/null cmd_rc=$? else if [[ -n ${NODE_MAP[_$repository]} ]]; then SITE=${NODE_MAP[_$repository]} SITE=${SITE##*\(} SITE=${SITE%\)} if [[ -n $SITE && \ "$(clodmget -n -f name HACMPsite | tr '\n' ' ') " == *\ $SITE\ * ]] then DISK_DATA=${NODE_MAP[_$repository]} DISK_DATA=${DISK_DATA/\(/:$repository:} DISK_DATA=${DISK_DATA%\)} cmd_rc=$RC_SUCCESS else SITE="" fi fi if [[ -z $SITE ]]; then for SITE in $(clodmget -n -f name HACMPsite); do if [[ -n ${_ENV_ARGS[SITE]} && ${_ENV_ARGS[SITE]} != $SITE ]] then continue fi #=================================================== # Hide STDERR here, since we're forced to try all # all known sites... and for sure only one of them # will be correct! Errors from the others are of # no use, and will confuse the customer. #=================================================== CL=$LINENO REFNODE=$node KLIB_HACMP_is_known_repository "$repository" "$SITE" DISK_DATA 2>/dev/null cmd_rc=$? (( $cmd_rc == RC_SUCCESS )) && break done fi fi else CL=$LINENO KLIB_HACMP_is_known_repository "$repository" "" DISK_DATA 2>/dev/null cmd_rc=$? fi if [[ $cmd_rc != $RC_SUCCESS && $(clodmget -n -f backup_repository HACMPsircol) == *${repository}* ]]; then #====================================================================== : The pvid:${repository} is not part of known repository disk list but : exists in HACMPsircol, so it is invalid pvid entry. # Set return code to RC_SUCCESS and continue for deletion #========================================================================= cmd_rc=$RC_SUCCESS if [[ $CLUSTER_TYPE == "LC" ]]; then site_id=$(clodmget -n -f id -q "backup_repository like *${repository}*" HACMPsircol) site=$(clodmget -q "id=$site_id" -n -f name HACMPsite) fi fi if (( $cmd_rc != RC_SUCCESS )); then if [[ -n $site ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 193 '\nERROR: "%1$s" does not appear to exist within site "%2$s", or is not a repository.\n\n' "$ORIGINAL_REPOS" "$site" 1>&2 elif (( COUNT > 1 )); then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 928 '\nERROR: repository disk "%1$s" could not be uniquely identified on all the relevant cluster nodes.\n\n' "$ORIGINAL_REPOS" 1>&2 else typeset ERRMSG=$(cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 464 '\nERROR: "%1$s" does not appear to exist, or is not a repository.\n\n' "$ORIGINAL_REPOS") ERRMSG=${ERRMSG%%+([[:space:]])} if [[ -n $node ]]; then ERRMSG="$ERRMSG (NODE=$node)" elif [[ -n $REFNODE ]]; then ERRMSG="$ERRMSG (NODE=$REFNODE)" fi print -u2 -- "$ERRMSG\n" fi dspmsg -s $CLMGR_SET $CLMGR_MSGS 168 "Available Repositories:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_repositories 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 else print -- "$DISK_DATA" | IFS=: read DEVNAME PVID JUNK REPO_PVID=$(clodmget -n -f repository HACMPsircol) PVID=${PVID//0000000000000000/} REPO_PVID=${REPO_PVID//0000000000000000/} if [[ -n ${PVID} && ${REPO_PVID} == ${PVID} ]] then ACTIVE_REPOS=1 if /usr/lib/cluster/incluster then cmd_rc=$RC_INCORRECT_INPUT cl_dspmsg -s 23 utilities 31 'Can not remove the active repository disk %1$s.\n' "($DEVNAME, $ORIGINAL_REPOS)" 1>&2 fi else ACTIVE_REPOS=0 fi fi if (( $cmd_rc == RC_SUCCESS )); then typeset repos_pvid=$repository if [[ -n $DISK_DATA ]]; then repos_pvid=${DISK_DATA%:*} repos_pvid=${repos_pvid#*:} fi if (( ! ACTIVE_REPOS )) then typeset siteOpt="" if [[ $site == *([[:space:]]) && $SITE != *([[:space:]]) ]] then siteOpt=" -S $SITE" elif [[ $site != *([[:space:]]) ]] then siteOpt=" -S $site" fi print -- "$0()[$LINENO]($SECONDS): clmanagerepos -r -d $repos_pvid -n $REFNODE$siteOpt" >>$CLMGR_TMPLOG # Always log commands clmanagerepos -r -d $repos_pvid $siteOpt cmd_rc=$? print -- "$0()[$LINENO]($SECONDS): clmanagerepos RC: $cmd_rc" >>$CLMGR_TMPLOG else # : clmanagerepos will not remove a primary repository : from HACMPsircol, even if the CAA cluster does not : exist yet. So we do it manually. # print "$0()[$LINENO]($SECONDS): print \"HACMPsircol: repository=\" | odmchange -o HACMPsircol -q \"repository=$repos_pvid\"" >>$CLMGR_TMPLOG print "HACMPsircol: repository=" | odmchange -o HACMPsircol -q "repository=$repos_pvid" if [[ $(clodmget -n -f repository HACMPsircol) == *${repos_pvid}* ]] then cmd_rc=$RC_ERROR else cmd_rc=$RC_SUCCESS fi print "$0()[$LINENO]($SECONDS): odmchange RC: $cmd_rc" >>$CLMGR_TMPLOG fi fi (( rc == RC_UNKNOWN )) && rc=$cmd_rc || (( rc |= cmd_rc )) done # End of the repositories loop 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' \ "delete repository -h" "REPOSITORY:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_delete_repository()" #============================================================================ # # 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_delete_repository =head1 VERSION Version Number: 1.12.1.2 Last Extracted: 9/22/16 18:04:26 Last Changed: 9/20/16 04:19:18 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_delete_repository.sh, hacmp.assist, 61haes_r721, 1638B_hacmp721 =head1 SYNOPSIS clmgr delete repository {[,,...] | ALL} \ [ SITE= ] \ [ NODE= ] =head1 DESCRIPTION Deletes one or more repositories from the cluster configuration. Backup repositories can always be removed, but the primary repository can only be removed if the CAA cluster configuration has not been created yet. =head1 ARGUMENTS 1. repositories [REQUIRED] [string] One or more (comma or space separated) repositories to attempt to delete. 2. site [OPTIONAL] [string] The site that this repository services. 3. refnode [OPTIONAL] [string] The label of node to use as a reference for resolving the specified disk names. This is only useful if device names are specified instead of PVIDs. If no node is provided, and effort is made to automatically find a suitable reference node. =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. 2005,2010 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 #==============================================================================