#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2019,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_is_known_repository.sh 1.15.1.1 # # 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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_repository.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_is_known_repository # # Description: This is the main, FPATH function that is invoked by clmgr # to determine if the specified disk, in device name or PVID # format, is a CAA repository disk. # # Inputs: See the "devDoc()" function, below. # # Outputs: If the third argument is provided, it is established as # a reference, and all data about the provided disk is # stored inside of it. Other than that, the only output # is any error messages that might occur. # # 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_is_known_repository { . $HALIBROOT/log_entry "$0()" "$CL" : version=@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_is_known_repository.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM : INPUTS: $* typeset cand_disk=${1//\"/} typeset site=${2//\"/} if (( $# >= 3 )) && [[ -n $3 ]] then typeset -n disk_data=${3//\"/} disk_data="" else typeset disk_data="" fi if (( $# >= 4 )) && [[ -n $4 ]] then typeset DISK_INFO=${4//\"/} fi [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset line= id= ALL_DISKS= junk= typeset cand_name= cand_pvid= cand_uuid= typeset repos_name= repos_pvid= repos_uuid= typeset IDENTIFIERS="" REM="" #================= : Validate input #================= if [[ -z $cand_disk ]]; 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 [[ $DISK_INFO != *:* ]]; then typeset NODES=$REFNODE # Can be set in external env if [[ -z $NODES ]]; then if [[ -n $site ]]; then NODES=$(clodmget -n -f nodelist -q name=$site HACMPsite) else NODES=$(clodmget -n -f name -q object=COMMUNICATION_PATH HACMPnode) fi NODES=$(CL=$LINENO trim "$NODES") fi #====================================== : Extract the data for the given disk #====================================== CL=$LINENO getDiskData "$cand_disk" "$NODES" IDENTIFIERS 1 print -- "$IDENTIFIERS" |\ IFS=: read cand_name cand_pvid cand_uuid REFNODE REM else #====================================================== : As a performance optimization, if the data for disk : "$cand_disk" has already been collected by : the caller, also via getDiskData, then there is no : reason to invoke it again to collect the same info. #====================================================== print -- "$DISK_INFO" |\ IFS=: read cand_name cand_pvid cand_uuid REFNODE REM fi ALL_DISKS=$(CL=$LINENO list_disks $REFNODE) if [[ $cand_name == *([[:space:]]) ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$cand_disk" 1>&2 log_return_msg "$RC_ERROR" "$0()" "$LINENO" return $? elif [[ $cand_vg != *([[:space:]]) && $cand_vg != "None" ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 256 '\nERROR: disk "%1$s" is already in use within volume group "%2$s".\n\n' "$cand_disk" "$cand_vg" 1>&2 log_return_msg "$RC_INCORRECT_INPUT" "$0()" "$LINENO" return $? fi #===================================================== : Create a list of all, already-defined repositories #===================================================== # Create the right filter # For NSC or SC: repositories are in a unique HACMPsircol which id=0 # For LC: repositories are in two HACMPsircol, one for each site, the id of site has to found first. typeset FILTER_SITE="" if [[ $CLUSTER_TYPE == "LC" && -n $site ]] then typeset FILTER_SITEID=$(clodmget -n -q "name=${site}_sircol" -f id HACMPsircol) FILTER_SITE="-q id=${FILTER_SITEID}" # # For NSC or SC, the 'id' qualifier can be dispensed # fi typeset KNOWN_REPOSITORIES=$(clodmget -n $FILTER_SITE -f repository HACMPsircol) typeset backups=$(clodmget -n $FILTER_SITE -f backup_repository HACMPsircol) [[ -n $backups ]] && KNOWN_REPOSITORIES="$KNOWN_REPOSITORIES $backups" KNOWN_REPOSITORIES=${KNOWN_REPOSITORIES//0000000000000000/} for disk in ${KNOWN_REPOSITORIES//,/ }; do #=========================================================== : Extract the remaining data for the given disk, so that a : complete comparison can be done. In other words, if a : device name was provided, then the PVID and UUID need to : be collected so they can be compared, too, if needed. #=========================================================== print -- "$ALL_DISKS" | grep -w "$disk" |\ read repos_name repos_pvid repos_vg repos_uuid REM [[ -z $repos_name ]] && continue if [[ $cand_name == $repos_name || \ $cand_pvid == $repos_pvid ]] then rc=$RC_SUCCESS break elif [[ $cand_uuid != *([[:space:]]) && \ $repos_uuid != *([[:space:]]) && \ $cand_uuid == $repos_uuid ]] then rc=$RC_SUCCESS break fi done if (( $rc == RC_SUCCESS )); then disk_data="$repos_name:$repos_pvid:$repos_uuid" fi (( $rc == RC_UNKNOWN )) && rc=$RC_NOT_FOUND fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_is_known_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_is_known_repository =head1 SYNOPSIS Determines if the specified disk is already in use as a repository. If so, a zero is returned, otherwise a non-zero is returned. In addition, the various identifiers for the disk are returned in the format: NAME:PVID:UUID =head1 DESCRIPTION Determines if the specified repository is configured within the cluster. =head1 ARGUMENTS 1. cand_disk [REQUIRED] [string] The label of the candidate disk that is to be identified as a repository (or not). 2. site [OPTIONAL] [string] A site label, that limits which nodes the repository is validated against. 3. disk_data [OPTIONAL] [string reference] A reference to a string in which the disk device name, PVID, and UUID will be stored/returned. =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 #==============================================================================