#!/bin/sh

##########################################################################
#   Script description:
#       Main menu for cluster admin tasks
#       
#   History:
#   Date        Name        Modification
#   2014-01-08  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

while true; do

    clear
    spcm-banner
    cat << EOM

Nodes must be configured for remote IPMI power-on to utilize the power on
features here.  This may require some BIOS setup.  Use auto-ipmi-install and
auto-ipmi-remote-access for the rest.

1.. Power on backup head node
2.. Power on file servers
3.. Power on compute nodes
4.. Power on vis nodes
5.. Power on nodes by hostname
6.. Shut down idle compute nodes
7.. Power on drained compute nodes
8.. Shut down cluster
Q.. Quit

EOM

    printf "Selection? "
    read selection
    clear
    case $selection in
    1)
	cluster-ipmi-power-on backup
	;;
    
    2)
	cluster-ipmi-power-on io
	;;
    
    3)
	cluster-ipmi-power-on compute
	;;
    
    4)
	cluster-ipmi-power-on vis
	;;
    
    5)
	printf "Enter hostnames separated by space\n"
	read hostnames
	for host in $hostnames; do
	    if [ ${host##*-} != mgmt ]; then
		host=$host-mgmt
	    fi
	    auto-ipmi-remote-power $host on
	done
	;;
    
    6)
	cluster-power-saver
	;;
    
    7)
	cluster-power-waster
	;;

    8)
	cluster-shutdown
	;;

    Q|q)
	exit 0
	;;
    
    *)
	printf "Invalid selection: '$selection'\n"
	;;
    esac
    pause
done
