blob: 8b37c5da27e6b03def3a203bfe701da53e7cf45b [file] [log] [blame]
Thomas Vachuska76188892017-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
11[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
12. $ONOS_ROOT/tools/build/envDefaults
13
14node=${1:-$OCI}
15cmd=${2:-on}
16
17if [ "$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
24elif [ "$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
31else
32 echo "usage: $(basename $0) node-ip {on|off}" >&2 && exit 1
33fi
34