blob: d0724133c62cd1cf76fcc2e21f16ec8c69e92316 [file] [log] [blame]
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -08001#!/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 Hall78c098d2018-06-05 11:04:24 -070011function usage() {
12 echo "usage: $(basename $0) node-ip {on|off} [user]" >&2 && exit 1
13}
14
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080015[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
16. $ONOS_ROOT/tools/build/envDefaults
17
18node=${1:-$OCI}
19cmd=${2:-on}
Jon Hall7e65d942018-04-27 09:27:32 -070020user=${3:$(id -un)}
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080021
Jon Hall78c098d2018-06-05 11:04:24 -070022if [ "$node" = "--help" ]; then
23 usage
24
25elif [ "$cmd" = "on" ]; then
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080026 if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then
Jon Hall7e65d942018-04-27 09:27:32 -070027 curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOn&nodeIp=$node&user=$user"
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080028 else
29 onos-service $node start
30 fi
31
32elif [ "$cmd" = "off" ]; then
33 if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then
Jon Hall7e65d942018-04-27 09:27:32 -070034 curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOff&nodeIp=$node&user=$user"
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080035 else
Jon Hall7e65d942018-04-27 09:27:32 -070036 onos-die $node
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080037 fi
38
39else
Jon Hall78c098d2018-06-05 11:04:24 -070040 usage
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080041fi
42