#!/bin/sh

. /usr/local/lib/vmware.sh

if [ $# -eq 1 ]; then
    mode="power.shutdown"
elif [ $# -eq 2 ]; then
    case $2 in
	hard)
            mode="power.off"
	    ;;
	soft)
            mode="power.shutdown"
	    ;;
	default)
            echo "Invalid power mode $2" 1>&2
	    exit 1
	    ;;
    esac
else
    echo "Usage: `basename $0` <vm> [hard|soft]" 1>&2
    exit 1
fi

vm="$1"

vmid="`vmid \"${vm}\"`"
if [ "${vmid}" = "" ]; then
    echo "Cannot find virtual machine ${vm}" 1>&2
    exit 1
fi

vmware-vim-cmd vmsvc/${mode} ${vmid}
