#!/bin/bash

# heartbeat STONITH module for powerman

PATH=/bin:/usr/sbin:$PATH

#ha_logger -t heartbeat "powerman stonith agent called with args: $*"

case $1 in
gethosts)
	exec pm -h $serverhost -lx
	;;
on)
	exec pm -h $serverhost -1 $2
	;;
off)
	exec pm -h $serverhost -0 $2
	;;
reset)
	if [ "$poweroff" == "1" ]; then
		exec pm -h $serverhost -0 $2
	else
		exec pm -h $serverhost -c $2
	fi
	;;
status)
	exec pm -h $serverhost -l >/dev/null
	;;
getconfignames)
	echo serverhost
	echo poweroff
	exit 0
	;;
getinfo-devid|getinfo-devname|getinfo-devdescr)
	echo "powerman STONITH device"
	exit 0
	;;
getinfo-devurl)
	echo "http://powerman.sourceforge.net/"
	exit 0
	;;
getinfo-xml)
	cat <<PMEOL
<parameters>
 <parameter name="serverhost" unique="1" required="1">
  <content type="string" default="localhost:10101"/>
  <shortdesc lang="en">host:port of powerman server</shortdesc>
  <longdesc lang="en">
  Specify the host:port of the powerman server, e.g. pmserver:10101
  </longdesc>
 </parameter>

 <parameter name="poweroff" unique="0" required="0">
  <content type="string" default="0"/>
  <shortdesc lang="en">Power off when given reset command</shortdesc>
  <longdesc lang="en">
  For V1 heartbeat which always resets to fence, power off when given
  the reset command.
  </longdesc>
 </parameter>
</parameters>
PMEOL
	exit 0
	;;
*)
	exit 1
	;;
esac
