Ayaka Koshibe | aec62962 | 2015-01-05 20:33:29 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Allows a select group of commands to be sent to all ONOS instances in a cell. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
Thomas Vachuska | 7816793 | 2016-02-12 13:13:31 -0800 | [diff] [blame] | 6 | echo "This command has been deprecated and will be removed after Falcon release" |
| 7 | echo "Please use the 'stc setup|shutdown|teardown' command instead" |
| 8 | |
Ayaka Koshibe | aec62962 | 2015-01-05 20:33:29 -0800 | [diff] [blame] | 9 | set -o pipefail |
| 10 | IFS=$'\n' |
| 11 | |
| 12 | source ogroup-opts |
| 13 | |
| 14 | function err() { |
| 15 | printf '%s: %s: %s\n' "$(basename $0)" "$1" "$2" >&2 |
| 16 | usage >&2 |
| 17 | exit 1 |
| 18 | } |
| 19 | |
| 20 | function usage() { |
| 21 | cat << EOF |
| 22 | |
| 23 | usage: $(basename $0) <help|[command]> |
| 24 | |
| 25 | Sends a command to all ONOS instances in the current cell. Currently supported |
| 26 | commands are: $GOPTS |
| 27 | |
| 28 | options: |
| 29 | [command] : A command to send to the instances. |
| 30 | help : Displays this message and exits. |
| 31 | |
| 32 | notes: |
| 33 | Hitting <TAB> will display the options for $(basename $0). |
| 34 | |
| 35 | EOF |
| 36 | } |
| 37 | |
| 38 | # gets the utility name |
| 39 | function 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 Koshibe | ebb5444 | 2015-01-09 14:22:19 -0800 | [diff] [blame] | 55 | OCIS=( $(env | sed -ne 's:OC[0-9]\{1,\}=\(.*\):\1 :g p' | sort -k1) ) |
Ayaka Koshibe | aec62962 | 2015-01-05 20:33:29 -0800 | [diff] [blame] | 56 | if [ -z "$OCIS" ]; then |
| 57 | printf "no controller instances, quitting early" >&2 && exit 0 |
| 58 | fi |
| 59 | |
| 60 | CMD_HELP=false |
| 61 | while [ $# -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 |
| 86 | done |
| 87 | |
| 88 | ( $CMD_HELP ) && $cmd '-h' && exit 0 |
| 89 | |
| 90 | # TODO: verbose-mode and cleanup |
| 91 | for i in ${OCIS[@]}; do |
| 92 | ${cmd} $(echo ${args[@]}) "$i" 2>/dev/null & |
| 93 | done |