#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/reconfig_resource_acquire_fence.sh 1.8.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2002,2013 
# 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 
# @(#)36	1.8.1.1 src/43haes/usr/sbin/cluster/events/reconfig_resource_acquire_fence.sh, hacmp.dare, 61haes_r714 7/29/13 15:00:57

#########################################################################
#
#       Name:           reconfig_resource_acquire_fence                 
#
#       Description:    This script is called during a reconfig          
#                       resource event to process fencing actions as
#                       directed by the clstrmgr
#                                                                   
#       Arguments:      none                                   
#                                                             
#       Returns:        0       success                      
#                       1       failure                     
#                       
#########################################################################

#########################################################################
#                                                                       #
#       Main start here                                                 #
#                                                                       #
#########################################################################

PROGNAME=$(basename ${0})
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"

DCD="/etc/es/objrepos"
SCD="/usr/es/sbin/cluster/etc/objrepos/stage"
ACD="/usr/es/sbin/cluster/etc/objrepos/active"

set -a
eval $(ODMDIR=$ACD cllsparam -n $LOCALNODENAME)
set +a

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
[[ "$VERBOSE_LOGGING" == "high" ]] && version='1.8.1.1'

#
# this is the working directory for DARE - the location must
# match the declaration in the other scripts involved
#
TEMPPATH="/var/hacmp/log/HACMP_RESOURCES"

export EVENT_TYPE=$PROGNAME       # Tell other scripts who called them
STATUS=0

#
# swap ODMs first. This is necessary because the clstrmgr reads from ACD
# step 1: move the acd to a staging area
#
mv $ACD $TEMPPATH/
if (( $? != 0 ))
then
        CMD="mv"
        cl_log 701 "ERROR: Received failed return code from command: $CMD\n" $CMD
        exit 1
fi

#
# step 2: move the scd (incoming config) to acd
#
mv $SCD $ACD
if (( $? != 0 ))
then
        CMD="mv"
        cl_log 701 "ERROR: Received failed return code from command: $CMD\n" $CMD
        exit 1
fi

#
# now call the clstrmgr for the calculation of fencing actions
#
if ! process_resources "RECONFIG_RESOURCE_ACQUIRE_FENCE"
then
    STATUS=1
fi

#
# now we can undo the odm swap above - first moving the acd back to scd
#
mv $ACD $SCD
if (( $? != 0 ))
then
        CMD="mv"
        cl_log 701 "ERROR: Received failed return code from command: $CMD\n" $CMD
        exit 1
fi

#
# now move the temporary back to acd
#
mv $TEMPPATH/active $ACD
if (( $? != 0 ))
then
        CMD="mv"
        cl_log 701 "ERROR: Received failed return code from command: $CMD\n" $CMD
        exit 1
fi

exit $STATUS

