####################################################################
# (C) Copyright 2010-2015 Hewlett-Packard Development Company, L.P.
# @(#) Metrocluster CAEVA Easy deployment  Script.
# @(#) Product Name                :  HP Metrocluster CAEVA
# @(#) Product Version             :  B.12.00.30 
#
# *** Note: This file MUST NOT be edited. *****
#
# Any changes made to it will be overwritten when you upgrade to the
# next release of HP Serviceguard.
#
# Changing this file may lead to unrecoverable package startup
# and/or shutdown problems.
#
###################################################################

if [ -f /etc/redhat-release ]; then
  DISTRO="REDHAT"
  CMCLUSTER="/usr/local/cmcluster"
else
  DISTRO="SUSE"
  CMCLUSTER="/opt/cmcluster"
fi


cluster_nodes=` cmviewcl -s config  -f line | grep "node:" |grep "name=" | awk '{FS="=";print $2}'`
uniq_dr=""
set -a final_output
output=""

function do_eva_stuff {
device=$1

if [[ -f /usr/sbin/evainfo ]];then
        device_wwn=`/usr/sbin/evainfo -d $device | grep $device | awk '{print $3
}' 2>/dev/null `
else
	echo "Evainfo utility not found "
        return 1
fi


output=`${CMCLUSTER}/bin/mccaeva/DREVAGetAttributes $device_wwn $cluster_nodes`

if [[ $? -ne 0 ]];then
   return 1
else
   dr_group=`echo "$output" | grep "DR_GROUP_NAME" |awk '{print $2}'`
   if [[ -z "$uniq_dr" ]];then
      uniq_dr=$dr_group
      final_output[${#final_output[@]}]=$output
      return  0
   elif [[ "$dr_group" = "$uniq_dr" ]];then
      final_output[${#final_output[@]}]=$output
     return 0
   else
    echo "The disks belong to multiple DR Groups " $dr_group " " $uniq_dr
    exit 1
   fi
fi

}

for disk in $@
do
	do_eva_stuff $disk
  
done

if [[ ${#final_output[@]} -ne 0 ]];then
echo "dts/caeva/DT_APPLICATION_STARTUP_POLICY Availability_Preferred"
echo "dts/caeva/WAIT_TIME	0"
echo "dts/caeva/QUERY_TIME_OUT	300"
echo "${final_output[*]}"
else
echo "$output"
fi
