#! /bin/sh # # $Id: cluster_client_validate.sh,v 1.8 2006/04/24 15:55:17 castrv Exp $ Copyright (c) 2005-2006, EMC Corporation. # # # Copyright (c) 2005-2006 EMC Corporation. # # All rights reserved. This is an UNPUBLISHED work, and # comprises proprietary and confidential information of EMC. # Unauthorized use, disclosure, and distribution are strictly # prohibited. Use, duplication, or disclosure of the software # and documentation by the U.S. Government is subject to # restrictions set forth in a license agreement between the # Government and EMC or other written agreement specifying # the Government's rights to use the software and any applicable # FAR provisions, such as FAR 52.227-19. # # Validate method for NetWorker Client (LGTO.clnt resource type) # This method validates the clientname and owned_paths properties # of the resource. The Validate # method gets called in two scenarios. When the resource is being created and # when a resource property is getting updated. When the resource is being # created, this method gets called with the -c flag and all the system-defined # and extension properties are passed as command-line arguments. # When a resource # property is being updated, the Validate method gets called with the -u flag, # and only the property/value pair of the property being updated is passed as a # command-line argument. # # ex: When the resource is being created command args will be # # nw_client.validate -c -R <..> -G <...> -T <..> -r ... # -x .... -g .... # # when the resource property is being updated # # nw_client.validate -u -R <..> -G <...> -T <..> -r # OR # nw_client.validate -u -R <..> -G <...> -T <..> -x # # parse program arguments. # parse_args() { while [ $# -gt 0 ] do case $1 in -R ) RESOURCE_NAME=$2 shift ;; -T ) RESOURCETYPE_NAME=$2 shift ;; -G ) RESOURCEGROUP_NAME=$2 shift ;; -r ) # The method is not accessing any system defined # properties, so this is a no-op. shift ;; -g ) # The method is not accessing any resource group # properties, so this is a no-op. shift ;; -c ) # Indicates the Validate method is being called while # creating the resource, so this flag is a no-op. ;; -u ) # Indicates the updating of a property when the # resource already exists. If the update is to the # extension property then extention should appear in the # command-line arguments. If it does not, the method must # look for it specifically using scha_resource_get. UPDATE_PROPERTY=1 ;; -x ) # Extension property list. Separate the property and # value pairs using "=" as the separator. PROPERTY=`echo $2 | awk -F= '{print $1}' | \ tr "[A-Z]" "[a-z]"` VAL=`echo $2 | awk -F= '{print $2}'` # If the Clientname extension property is found on the # command line, note its value. if [ X${PROPERTY} = "Xclientname" ]; then CLIENTNAME=$VAL CLIENTNAME_FOUND=1 elif [ X${PROPERTY} = "Xowned_paths" ]; then OWNED_PATHS=$VAL OWNED_PATHS_FOUND=1 elif [ X${PROPERTY} = "Xnetwork_resource" ]; then NETWORK_RESOURCE=$VAL NETWORK_RESOURCE_FOUND=1 fi shift ;; * ) # Just ignore everything else... ;; esac shift done } ############################################################################## # # MAIN # ############################################################################## PATH=/bin:/usr/bin:/usr/cluster/bin:/usr/sbin:/usr/proc/bin:$PATH export PATH if [ -f /bin/hostname ]; then HOSTNAME=`/bin/hostname` elif [ -f /usr/ucb/hostname ]; then HOSTNAME=`/usr/ucb/hostname` elif [ -f /usr/bsd/hostname ]; then HOSTNAME=`/usr/bsd/hostname` elif [ -f /usr/local/bin/hostname ]; then HOSTNAME=`/usr/local/bin/hostname` else HOSTNAME= fi if [ X${HOSTNAME} = X ]; then HOSTNAME=`uname -n` fi BASE=`basename $0` # Obtain the syslog facility to use to log messages. SYSLOG_FACILITY=`scha_cluster_get -O SYSLOG_FACILITY` LOGERR="logger -t '$HOSTNAME:$BASE' -p ${SYSLOG_FACILITY}.err" LOGINFO="logger -t '$HOSTNAME:$BASE' -p ${SYSLOG_FACILITY}.info" # Set the Value of extention properties to null. # Later, this method retrieves the value # of the extention properties from the command line or using scha_resource_get. UPDATE_PROPERTY=0 CLIENTNAME="" CLIENTNAME_FOUND=0 OWNED_PATHS="" OWNED_PATHS_FOUND=0 NETWORK_RESOURCE="" NETWORK_RESOURCE_FOUND=0 # Parse the arguments that have been passed to this method. parse_args $* # If the validate method is being called due to the updating of properties # try to retrieve the value of the extension property from the command # line. Otherwise, obtain the value of the extension property # using scha_resource_get. if [ $UPDATE_PROPERTY = 1 -a $CLIENTNAME_FOUND = 0 ]; then CLIENTNAME=`scha_resource_get -G $RESOURCEGROUP_NAME -R $RESOURCE_NAME -O EXTENSION Clientname | tail +2` fi if [ $UPDATE_PROPERTY = 1 -a $OWNED_PATHS_FOUND = 0 ]; then OWNED_PATHS=`scha_resource_get -G $RESOURCEGROUP_NAME -R $RESOURCE_NAME -O EXTENSION Owned_paths | tail +2` else # replace ',' with blanks so for the for loop below OWNED_PATHS=`echo $OWNED_PATHS | sed s/\,/\ /g` fi if [ $UPDATE_PROPERTY = 1 -a $NETWORK_RESOURCE_FOUND = 0 ]; then NETWORK_RESOURCE=`scha_resource_get -G $RESOURCEGROUP_NAME -R $RESOURCE_NAME -O EXTENSION Network_resource | tail +2` fi # Verify that the extension properties have values. If not there is a failure # and exit with status 1. # Clientname and owned_paths are required properties, # Network_resource is optional if [ -z "$CLIENTNAME" ]; then $LOGERR "Validate method for resource "$RESOURCE_NAME " failed" $LOGERR "Clientname extension propery doesn't have a value" exit 1 fi if [ -z "$OWNED_PATHS" ]; then $LOGERR "Validate method for resource "$RESOURCE_NAME " failed" $LOGERR "Owned_paths extension propery doesn't have a value" exit 1 fi # Validate Clientname extension property value if [ -z "${NETWORK_RESOURCE}" ]; then # Clientname should be a valid SUNW.SharedAddress or # SUNW.LogicalHostname resource IS_LH="FALSE" IS_LH=`scha_resource_get -R $CLIENTNAME -O IS_LOGICAL_HOSTNAME` IS_SA="FALSE" IS_SA=`scha_resource_get -R $CLIENTNAME -O IS_SHARED_ADDRESS` if [ ! \( "X${IS_LH}" = "XTRUE" -o "X${IS_SA}" = "XTRUE" \) ] ; then $LOGERR "Validate method for resource "$RESOURCE_NAME " failed" $LOGERR "Network_resource is not specified, in this case \ Clientname extension propery should specify a valid \ SUNW.SharedAddress or SUNW.LogicalHostname resource" exit 1 fi else # Clientname should be in the hostnamelist extenstion property of the # Network_resource resouce HOSTNAMELIST=`scha_resource_get -R ${NETWORK_RESOURCE} -O EXTENSION HostnameList | tail +2` clientname_found=false for host in ${HOSTNAMELIST} ; do if [ ${CLIENTNAME} = ${host} ] ; then clientname_found=true fi done if [ "${clientname_found}" = "false" ] ; then $LOGERR "Validate method for resource "$RESOURCE_NAME " failed" $LOGERR "Clientname ${CLIENTNAME} should be in the hostnamelist extension property of the Network_resource resource ${NETWORK_RESOURCE}" exit 1 fi fi # Validate the actual owned_paths property value. # Check if owned_paths directories are accessible. for dir in $OWNED_PATHS ; do if [ ! -d $dir -a ! -c $dir ]; then $LOGERR "Validate method for resource "$RESOURCE_NAME " failed" $LOGERR "Owned_paths extension propery has invalid value" $LOGERR "$dir is not a directory or character special file" exit 1 fi done # Log a message indicating that the Validate method was successful. $LOGINFO "Validate method for resource "$RESOURCE_NAME \ " completed successfully" exit 0