#!/bin/bash

#       Copyright (c) Stratus Technologies Bermuda Ltd., 2008.
#       All Rights Reserved. Unpublished rights reserved
#       under the copyright laws of the United States.
# 
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU Lesser General Public License as published
#       by the Free Software Foundation; version 2.1 only. with the special
#       exception on linking described in file LICENSE.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU Lesser General Public License for more details.

. /usr/libexec/xapi/cluster-stack/xhad/ha_rc

#
#   ha_set_host_weight   <class> <weight> 
#

#   Check parameter
if [ $# -lt 2 ]; then
    error "Missing parameter(s)" "" $MTC_EXIT_INVALID_PARAMETER
fi
if [ $# -gt 2 ]; then
    error "Invalid parameter(s)" "" $MTC_EXIT_INVALID_PARAMETER
fi

# exec weightctl
weightctl set "$1" "$2" || exit $?

# calldaemon to reload the weight file 
calldaemon reload_host_weight
retval=$?

# exit success if daemon is not present
if [ $retval -eq $MTC_EXIT_DAEMON_IS_NOT_PRESENT ]; then
    exit $MTC_EXIT_SUCCESS
fi
exit $retval
