blob: 1337e28dd637a391abdf91f1e21717d4b1ba924e [file] [log] [blame]
Ayaka Koshibeaec629622015-01-05 20:33:29 -08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Allows a select group of commands to be sent to all ONOS instances in a cell.
4# -----------------------------------------------------------------------------
5
Thomas Vachuska78167932016-02-12 13:13:31 -08006echo "This command has been deprecated and will be removed after Falcon release"
7echo "Please use the 'stc setup|shutdown|teardown' command instead"
8
Ayaka Koshibeaec629622015-01-05 20:33:29 -08009set -o pipefail
10IFS=$'\n'
11
12source ogroup-opts
13
14function err() {
15 printf '%s: %s: %s\n' "$(basename $0)" "$1" "$2" >&2
16 usage >&2
17 exit 1
18}
19
20function usage() {
21cat << EOF
22
23usage: $(basename $0) <help|[command]>
24
25Sends a command to all ONOS instances in the current cell. Currently supported
26commands are: $GOPTS
27
28options:
29 [command] : A command to send to the instances.
30 help : Displays this message and exits.
31
32notes:
33 Hitting <TAB> will display the options for $(basename $0).
34
35EOF
36}
37
38# gets the utility name
39function getcmd() {
40 # check that utility can be run in "batch-mode"
41 local isgopt=false
42 for c in $(printf '%s' "$GOPTS" | tr ' ' $'\n'); do
43 [ "$c" = "$1" ] && isgopt=true && break
44 done
45 if $isgopt ; then
46 printf 'onos-%s' "$1"
47 else
48 err 'unsupported command' "$1"
49 fi
50}
51
52# early sanity check for instances/arguments
53[ -z "$1" ] && usage && exit 0
54
Ayaka Koshibeebb54442015-01-09 14:22:19 -080055OCIS=( $(env | sed -ne 's:OC[0-9]\{1,\}=\(.*\):\1 :g p' | sort -k1) )
Ayaka Koshibeaec629622015-01-05 20:33:29 -080056if [ -z "$OCIS" ]; then
57 printf "no controller instances, quitting early" >&2 && exit 0
58fi
59
60CMD_HELP=false
61while [ $# -gt 0 ]; do
62 case "$1" in
63 'help')
64 usage && exit 0
65 ;;
66 '-'?)
67 err 'invalid flag' "$1" && exit 1
68 ;;
69 *)
70 cmd=$(getcmd $1) || exit 1
71 shift
72 # grab flags aimed at the utility being called.
73 argv=( $@ )
74 args=()
75 for i in "${!argv[@]}"; do
76 # 'help' is a parameter for us; '-h' is for the command
77 [ "${argv[$i]}" = 'help' ] && break
78 [ "${argv[$i]}" = '-h' ] && CMD_HELP=true
79 args[$i]="${argv[$i]}"
80 shift
81 done
82 continue
83 ;;
84 esac
85 shift
86done
87
88( $CMD_HELP ) && $cmd '-h' && exit 0
89
90# TODO: verbose-mode and cleanup
91for i in ${OCIS[@]}; do
92 ${cmd} $(echo ${args[@]}) "$i" 2>/dev/null &
93done