1
# -*- mode: shell-script -*-
3
# Control a system via ipmipower
7
power_change={{power_change}}
8
power_address={{power_address}}
9
power_user={{power_user}}
10
power_pass={{power_pass}}
11
power_driver={{power_driver}}
12
ipmipower={{ipmipower}}
13
ipmi_chassis_config={{ipmi_chassis_config}}
14
config={{config_dir}}/{{ipmi_config}}
16
# Determines the power command needed to execute the desired
17
# action. This function receives ${power_change} as argument.
18
formulate_power_command() {
20
'on') echo '--cycle --on-if-off' ;;
21
'off') echo '--off' ;;
23
echo "Got unknown power state from ipmipower: '$1'" >&2
28
# Determines the current state on which the machine finds itself.
29
# The argument passed comes from IPMI's stat command in the form:
30
# <ipmi-ip-address>: <on/off>
31
# This function evaluates whether it was <on/off>.
32
formulate_power_state() {
37
echo "Got unknown power state from ipmipower: '$2'" >&2
42
# Issue command to ipmipower, for the given system.
43
issue_ipmi_command() {
44
# See https://launchpad.net/bugs/1053391 for details of this workaround
46
if [ -n "$power_driver" ]
48
driver_option="--driver-type=$power_driver"
52
${ipmi_chassis_config} ${driver_option} -h ${power_address} -u ${power_user} -p ${power_pass} --commit --filename ${config}
54
${ipmipower} ${driver_option} -h ${power_address} -u ${power_user} -p ${power_pass} "$@"
58
# Get the given system's power state: 'on' or 'off'.
60
ipmi_state=$(issue_ipmi_command stat)
61
formulate_power_state ${ipmi_state}
65
if [ "$(get_power_state)" != "${power_change}" ]
67
power_command=$(formulate_power_command ${power_change})
68
issue_ipmi_command ${power_command}