#!/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 # @(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_compare_cluster.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM #============================================================================ # # Name: KLIB_HACMP_compare_cluster # # Description: This is the main, FPATH function that is invoked by clmgr # to compare clusters. It uses the "clccv" utility to # generate a json report. # # Inputs: See the "devDoc()" function at the bottom of this file. # # Outputs: None - generates a json file. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function at the bottom of this file for # the standard return code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_compare_cluster { . $HALIBROOT/log_entry "$0()" "$CL" : version="@(#) 7d4c34b 43haes/lib/ksh93/hacmp/KLIB_HACMP_compare_cluster.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM" : INPUTS: $* typeset hosts=${1//\"/} typeset DIRECTORY=${2//\"/} typeset DISABLE_EXPECT=${3//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset MSG="" typeset dOpt="" typeset eOpt="" #=================================== : Validate inputs #=================================== # clccv takes 1 or 2 host names: # 1) if one name is given it is assumed the local cluster configuration # will be used for comparison and the provided name is a node in a remote # cluster. # 2) if two names are given, they are both assumed to be nodes in # a remote cluster, though the clever user might give the hostname # of a cluster node in the same cluster as this one, thus achieving the # the same as (1) above. # # no matter what they must be comma separated, so we begin by checking # for that if [[ $hosts == *([[:space:]]) || $hosts != *,* ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 200 "\nERROR: missing required argument: %1\$s\n" "," 1>&2 rc=$RC_MISSING_INPUT # additional help message will be printed below fi : Directory arg must be a directory if [[ -n $DIRECTORY ]]; then dOpt="-d $DIRECTORY" if [[ $DIRECTORY != *([[:space:]])/* ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 106 "\nERROR: the specified path/file does not appear to be in absolute format:\n %1\$s\n\n" "$DIRECTORY" 1>&2 rc=$RC_NOT_FOUND else if [[ ! -d $DIERCTORY ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 136 "\nWarning: the directory in \"%1\$s\" does not yet exist.\n An attempt will be made to create that directory.\n\n" "$DIERCTORY" mkdir -p "$DIERCTORY" if [[ ! -d $DIERCTORY ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 201 "ERROR: failed to create \"%1\$s\".\n\n" "$DIERCTORY" 1>&2 rc=$RC_NOT_FOUND fi fi fi fi [[ -n "$DISABLE_EXPECT" ]] && eOpt="-E" #=================================================== : Invoke clccv for the comparison - clccv takes care of : all additional input validation #=================================================== if (( $rc == RC_UNKNOWN )) then print "$0()[$LINENO]($SECONDS): clccv -n $hosts $dOPT $eOPT" >>$CLMGR_TMPLOG # Always log commands clccv -n $hosts $dOpt $eOpt 2>>$CLMGR_TMPLOG rc=$? print "$0()[$LINENO]($SECONDS): clccv RC=$rc" >>$CLMGR_TMPLOG # Always log command result if (( $rc != RC_SUCCESS )); then # clccv will have shown detailed error information dspmsg -s $CLMGR_SET $CLMGR_MSGS 109 "\nERROR: the operation appears to have failed.\n\n" 1>&2 rc=$RC_ERROR 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 print -u2 "" 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" \ "compare cluster -h" "CLUSTER:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } #============================================================================ # # 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 even if the man pages are installed. # As a result of this, it is imperative that the information in # this SYNOPSIS be kept in sync with the man page information. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_compare_cluster =head1 SYNOPSIS clmgr compare cluster , \ [ DIRECTORY="/absolute/path/to/store/results" ] \ [ DISABLE_EXPECT ] NOTE: the alias for "cluster" is "cl". NOTE: aliases for "compare" are "comp", "diff". =head1 DESCRIPTION Compares the cluster configuration on the cluster nodes specified by host name. =head1 ARGUMENTS 1. hosts [REQUIRED] string Comma separated list of two hosts to compare. Either can be: o host name of a node in a remote cluster o host name of a node in a the same cluster as where this command is being run If only one host is given, it is assumed the local cluster will be used for the comparison. All remote hosts must be accessible using ssh and scp. The user may be prompted one or more times to enter that password. 2. DIRECTORY [OPTIONAL] string Path to use when saving the results of the comparison. Default is "/tmp". 3. DISABLE_EXPECT [OPTIONAL] PowerHA will use "expect" by default to reduce the number of times the user must enter a password. This flag specifies that expect should not be used, even if it is available. =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 #==============================================================================