#!/usr/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/usr/sbin/cluster/sa/wmq/sbin/cl_wmq_Utilities.sh 1.1 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011 # 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 # @(#)51 1.1 src/43haes/usr/sbin/cluster/sa/wmq/sbin/cl_wmq_Utilities.sh, hacmp, 61haes_r714 11/28/11 14:59:04 ####################################################################################### # Function:ServiceIP_Defined # # 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 ServiceIP_Defined { [[ "$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 : validate_Nodes # # Purpose : Validate if the Primary and takeover nodes are not repetetive. # # Arguments : PRIMNODE # TAKEOVER NODES # # Returns: 0 for Sucess # 1 for Failure # ###################################################################################################### function validate_Nodes { for node in $2 do [[ $1 == $node ]] && return 1 done return 0 } ####################################################################################################### # # Function : validate_AppName # # 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 validate_AppName { 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 } ##################################################################################################### # # Function : dir_fs_vg # # Purpose : If the directory is given it finds File system or VG. # dir_fs_vg $dir 0/1 # second argument 0 -- it return the VG # 1 -- it returns file system # # Args: # 1. directory # 2. 0/1 # # Returns : # 0 for success # 1 for failure # ####################################################################################################### function dir_fs_vg { [[ "$VERBOSE_LOGGING" == "high" ]] && set -x dir=$1 fs=$dir i=0 count=$(echo $dir|awk '{ n=split($1, A, "/");print n }') count=$(expr $count - 1) while [[ $i < $count ]] do i=$i m_fs=$(lsfs -c|grep $fs |grep -v grep) [[ $? == 0 ]] && { [[ $2 == 1 ]] && { fs_d=$(echo $m_fs|awk -F: '{print $1}') echo $fs_d return 0 } lv=$(echo $m_fs|awk -F: '{print $2}'|awk -F/ '{print $3}') vg=$(clodmget -q "name=$lv" -f parent -n CuDv) echo $vg return 0 } fs=$(echo $fs|cut -d "/" -f -`expr $count - $i`) i=$(expr $i + 1) done return 1 }