# @(#)29 1.3.1.1 src/43haes/usr/sbin/cluster/sa/tsmclient/sbin/cl_tsmcliUtilities.sh, hacmp.assist, 61haes_r714, 1415A_hacmp714 1/22/14 13:35:42 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/usr/sbin/cluster/sa/tsmclient/sbin/cl_tsmcliUtilities.sh 1.3.1.1 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 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 #---------------------------------------------------------------------------- # Function: # isVolumeGroupAlreadyDefined # # Purpose: # Checks to ensure the volume group passed in is not already defined to # PowerHA SystemMirror # # Arguments: # (1) Volume Group Name # # Returns: # 0 volume group IS defined to PowerHA SystemMirror # 1 volume group is NOT defined to PowerHA SystemMirror #---------------------------------------------------------------------------- function isVolumeGroupAlreadyDefined { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x typeset defVG=$1 typeset vgs vg rg clvt query resource_group >/dev/null 2>&1 if [[ $? == "0" ]];then RGS=$(clvt query resource_group) for rg in $RGS; do vgs=$(clvt query resource_group $rg | grep VOLUME_GROUP | awk -F'=' '{ print$2 }') vgs=${vgs//\"/} for vg in $vgs; do [[ "$vg" == "$defVG" ]] && { echo $rg return 0 } done vgs=$(clvt query resource_group $rg | grep \ CONCURRENT_VOLUME_GROUP | awk -F'=' '{ print $2 }') vgs=${vgs//\"/} for vg in $vgs; do [[ "$vg" == "$defVG" ]] && { echo $rg return 0 } done done fi return 1 } #---------------------------------------------------------------------------- # Function: # isServiceIPLabelAlreadyDefined # # Purpose: # Validate that the service IP label isn't already defined in the PowerHA SystemMirror # cluster. If it is already defined, report an error and exit this script # # Arguments: # (1) Service IP Label # # Return: # 1 if service IP label is not defined # 0 if service IP label is already defined #---------------------------------------------------------------------------- function isServiceIPLabelAlreadyDefined { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x typeset serviceIP=$1 clvt query resource_group >/dev/null 2>&1 if [[ $? == "0" ]];then RGS=$(clvt query resource_group) for rg in $RGS; do ips=$(clvt query resource_group $rg | grep \ SERVICE_LABEL | awk -F= '{ print $2 }') ips=${ips//\"/} for ip in $ips; do [[ "$ip" == "$serviceIP" ]] && { return 0 } done done fi return 1 } #---------------------------------------------------------------------------- # Function: # getServiceNetwork # # Purpose: # Determine the appropriate network to place the service IP label # on based on adapter count per network per node # # Arguments: # (1) list of nodes to find interfaces for # (2) network type in PowerHA SystemMirror # # Output: # network name to place service IP label on # # Returns: # 0 on success # 1 on failure #---------------------------------------------------------------------------- function getServiceNetwork { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x serv_addr_type=$1 NODES=$2 validv6Networks="" validv4Networks="" typeset NETWORKS=$(clvt query network | sort -u) typeset validNetworks typeset -A netXnodeCount for network in $NETWORKS do fam=$(clvt query network $network| awk -F= '$1 ~ /NET_FAMILY/ { print $2 }' | sed -e "s/\"//g") if [[ "$fam" == "2" ]] then validv6Networks=$(echo "$network $validv6Networks") else validv4Networks=$(echo "$network $validv4Networks") fi done INTERFACES=$(clvt query interface | sort -u) for interface in $INTERFACES; do node=$(clvt query interface $interface | awk -F= '$1 ~ /NODE/ {print $2 }' | sed -e "s/\"//g") net=$(clvt query interface $interface | awk -F= '$1 ~ /NETWORK/ {print $2 }' | sed -e "s/\"//g") [[ -n $node && -n $net ]] && { typeset -i count=${netXnodeCount[${net}_${node}]} (( count++ )) netXnodeCount[${net}_${node}]=$count } done typeset -i invalid=0 if [[ "$serv_addr_type" == "2" || -z $validv4Networks ]] then for network in $validv6Networks; do invalid=0 for node in $NODES; do [[ ${netXnodeCount[${network}_${node}]} == 0 ]] && { invalid=1 } done [[ $invalid == 0 ]] && { echo $network return 0 } done fi for network in $validv4Networks; do invalid=0 for node in $NODES; do [[ ${netXnodeCount[${network}_${node}]} == 0 ]] && { invalid=1 } done [[ $invalid == 0 ]] && { echo $network return 0 } done return 1 } ####################################################################################################### # # Function : validateNodes # # Purpose : Validate if the Primary and takeover nodes are not repetetive. # # Arguments : PRIMNODE # TAKEOVNODES # # Returns: 0 for Sucess # 1 for Failure # ###################################################################################################### function validateNodes { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x for node in $2 do [[ $1 == $node ]] && return 1 done return 0 } #---------------------------------------------------------------------------- # Function: # getUnusedName # # Purpose: # Obtain an un-used name for an PowerHA SystemMirror component (application, monitor, # resource group, etc) # # Arguments: # (1) by reference - name # (2) type - (as used in clvt command # resource_group | # application | # application_monitor, etc.) # # Output: # output contains the available name # # Returns: # 0 on success # 1 on failure #---------------------------------------------------------------------------- function getUnusedName { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x typeset name=$1 typeset type=$2 typeset newname=$name typeset ret typeset -i count=1 clvt query $type $newname >/dev/null 2>&1 ret=$? while [[ $ret == "0" ]]; do (( count++ )) # Give up after 9 attempts if (( $count > 9 )); then echo $name return 1 fi newname=${name:0:31} newname=${newname}${count} clvt query $type $newname >/dev/null 2>&1 ret=$? done echo $newname return 0 } ####################################################################################################### # # Function : validateAppName # # Purpose : Validate if the Application name entered has valid charactes. charecters can be # [a-z][A-z][0-9]_ # # Arguments :APPLICATION_ID # # Returns: 0 for Sucess # 1 for Failure # ###################################################################################################### function validateAppName { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x appname=$1 [[ -n ${appname//[a-zA-Z0-9_]/} ]] && return 1 return 0 } ##################################################################################################### # # Function : isipv6addr # # Purpose : Finds the address is IPv4 or IPV6 # # Args: # # # Returns : # 0 for success # 1 for failure (when the address is not IPv6) # ####################################################################################################### function isipv6addr { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x typeset v6addr=${1:-} abc=$(echo $v6addr|awk ' { n=split($1, A, ":") if(n==1) { print n exit } for(i=1; i<=n; i++) { if(length(A[i])) { if(i == n) printf "%s", A[i] else printf "%s:", A[i] } else { if(i==1) s=1 else s = 9-n for(j=1; j<=s; j++) printf "%s:", "0" } } }') if [[ $abc == 1 ]] then return 1 else return 0 fi } ################################################################################ ##################### # # Function : dir_fs_vg # # Purpose : Given a directory, find the containing filesystem or volume group. # # Args: directory name # 0 -- return the containing VG # 1 -- return the containing file system # # Returns : # 0 for success # 1 for failure # ################################################################################ ####################### function dir_fs_vg { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x dir=$1 typeset -i output_type=$2 # # the directory specified may be a subdirectory of the filesystem # e.g. given /tmp/foo, we want to find the filesystem, which is /tmp # so we recurse up through the path until we find a fs name # while [[ -n $dir ]] do # # is this a filesystem ? # LC_ALL=C lsfs -c| grep -v "^#MountPoint:" |grep ^${dir}: | \ IFS=: read fs lv rest if [[ -n $fs ]] then # # found something that matches a filesystem name - if # asked for a fs we are all done, but if we were asked # for a vg name, we need to map the corresponding lv # if (( output_type == 1 )) then echo $fs return 0 fi lv=${lv##*/} # strip of the /dev/ part vg=$(clodmget -q "name=$lv" -f parent -n CuDv) if [[ -n $vg ]] then echo $vg return 0 else # fatal error - could not map lv to a vg return 1 fi fi # # strip off the lowest level of the dir and try again # dir=${dir%/*} done # no matches - return error return 1 } ##################################################################################################### # # Function : same_participating_nodes # # Purpose : Finds participating nodes of the Resource Groups will have same nodes and same node # order. # # Args: # # first argument: Resource group name created by TSM client # second argument: remaining resource groups for whic TSM resource group will be checked # for same participating nodes # # Returns : # 0 for success # 1 for failure # ####################################################################################################### function same_participating_nodes { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x f_rg=$1 rgs=$2 typeset -A rgs_nodes f_nodes=$(clvt query resource_group $f_rg|grep NODES|awk -F= '{ print $2 }' | sed -e "s/\"//g") rgs_equal="" rgs_not_equal="" rgs_same="" for rg in $rgs do if [[ $rg != $f_rg ]];then t_nodes=$(clvt query resource_group $rg|grep NODES|awk -F= '{ print $2 }' | sed -e "s/\"//g") if [[ "$t_nodes" == "$f_nodes" ]];then rgs_nodes[$rg]=1 else for i in $t_nodes do found=0 for j in $f_nodes do [[ $i == $j ]] found=1 done [[ $found == 0 ]] && rgs_nodes[$rg]=0 done rgs_nodes[$rg]=2 fi fi done for rg in $rgs do if [[ ${rgs_nodes[${rg}]} == 0 ]];then rgs_not_equal=$(echo "$rgs_not_equal $rg") elif [[ ${rgs_nodes[${rg}]} == 1 ]];then rgs_equal=$(echo "$rgs_equal $rg") elif [[ ${rgs_nodes[${rg}]} == 2 ]];then rgs_same=$(echo "$rgs_same $rg") fi done [[ -n $rgs_not_equal ]] && return 1 [[ -n $rgs_equal && -n $rgs_same ]] && return 1 [[ -z $rgs_not_equal && -z $rgs_equal ]] && return 0 return 0 }