# IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminUtilities.sh 1.3 # # 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: # 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) network type in PowerHA SystemMirror # (2) list of nodes to find interfaces for # # 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 { 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 relyl 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 { 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 { 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 }