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 | |
| 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} |
| 16 | |
| 17 | if [ "$cmd" = "on" ]; then |
| 18 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
| 19 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOn&nodeIp=$node&user=$(id -un)" |
| 20 | else |
| 21 | onos-service $node start |
| 22 | fi |
| 23 | |
| 24 | elif [ "$cmd" = "off" ]; then |
| 25 | if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then |
| 26 | curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOff&nodeIp=$node&user=$(id -un)" |
| 27 | else |
| 28 | onos-die $node start |
| 29 | fi |
| 30 | |
| 31 | else |
| 32 | echo "usage: $(basename $0) node-ip {on|off}" >&2 && exit 1 |
| 33 | fi |
| 34 | |