blob: fc684ca5f8f320dec74dc45dd4086900c05ce777 [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
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}
Jon Hall7e65d942018-04-27 09:27:32 -070016user=${3:$(id -un)}
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080017
18if [ "$cmd" = "on" ]; then
19 if [ -n "$HARD_POWER_OFF" -a $ONOS_CELL = "borrow" ]; then
Jon Hall7e65d942018-04-27 09:27:32 -070020 curl -sS -X PUT "http://$CELL_WARDEN:4321/?cmd=powerOn&nodeIp=$node&user=$user"
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080021 else
22 onos-service $node start
23 fi
24
25elif [ "$cmd" = "off" ]; then
26 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=powerOff&nodeIp=$node&user=$user"
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080028 else
Jon Hall7e65d942018-04-27 09:27:32 -070029 onos-die $node
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080030 fi
31
32else
Jon Hall7e65d942018-04-27 09:27:32 -070033 echo "usage: $(basename $0) node-ip {on|off} user" >&2 && exit 1
Thomas Vachuska5ca0f7a2017-11-28 16:27:22 -080034fi
35