Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Provides a unioform way to simulate power on/off control over an ONOS node. |
| 4 | # If environment variable HARD_POWER_OFF is set and the ONOS_CELL value |
| 5 | # indicates that the cell is a borrowed shared cell LXC machine, it will use |
| 6 | # a REST call to warden, which then uses lxc-stop/lxc-start command to |
| 7 | # simulate a power control operations. Otherwise, it will just use the soft |
| 8 | # 'onos-die' command. |
| 9 | # ----------------------------------------------------------------------------- |
| 10 | |
| 11 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 12 | . $ONOS_ROOT/tools/build/envDefaults |
| 13 | |
| 14 | node=${1:-$OCI} |
| 15 | cmd=${2:-on} |
Jon Hall | cd72924 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 16 | user=${3:$(id -un)} |
Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 17 | |
| 18 | if [ "$cmd" = "on" ]; then |
| 19 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
Jon Hall | cd72924 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 20 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOn&nodeIp=$node&user=$user" |
Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 21 | else |
| 22 | onos-service $node start |
| 23 | fi |
| 24 | |
| 25 | elif [ "$cmd" = "off" ]; then |
| 26 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
Jon Hall | cd72924 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 27 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOff&nodeIp=$node&user=$user" |
Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 28 | else |
Jon Hall | cd72924 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 29 | onos-die $node |
Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 30 | fi |
| 31 | |
| 32 | else |
Jon Hall | cd72924 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 33 | echo "usage: $(basename $0) node-ip {on|off} user" >&2 && exit 1 |
Thomas Vachuska | 7618889 | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 34 | fi |
| 35 | |