Thomas Vachuska | 5ca0f7a | 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 | |
Jon Hall | 78c098d | 2018-06-05 11:04:24 -0700 | [diff] [blame] | 11 | function usage() { |
| 12 | echo "usage: $(basename $0) node-ip {on|off} [user]" >&2 && exit 1 |
| 13 | } |
| 14 | |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 15 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 16 | . $ONOS_ROOT/tools/build/envDefaults |
| 17 | |
| 18 | node=${1:-$OCI} |
| 19 | cmd=${2:-on} |
Jon Hall | 7e65d94 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 20 | user=${3:$(id -un)} |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 21 | |
Jon Hall | 78c098d | 2018-06-05 11:04:24 -0700 | [diff] [blame] | 22 | if [ "$node" = "--help" ]; then |
| 23 | usage |
| 24 | |
| 25 | elif [ "$cmd" = "on" ]; then |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 26 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
Jon Hall | 7e65d94 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 27 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOn&nodeIp=$node&user=$user" |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 28 | else |
| 29 | onos-service $node start |
| 30 | fi |
| 31 | |
| 32 | elif [ "$cmd" = "off" ]; then |
| 33 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
Jon Hall | 7e65d94 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 34 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOff&nodeIp=$node&user=$user" |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 35 | else |
Jon Hall | 7e65d94 | 2018-04-27 09:27:32 -0700 | [diff] [blame] | 36 | onos-die $node |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 37 | fi |
| 38 | |
| 39 | else |
Jon Hall | 78c098d | 2018-06-05 11:04:24 -0700 | [diff] [blame] | 40 | usage |
Thomas Vachuska | 5ca0f7a | 2017-11-28 16:27:22 -0800 | [diff] [blame] | 41 | fi |
| 42 | |