Jonathan Hart

Aliased $OCX variables to the X number for onos and onos-log commands.

I.e. running "onos 1" is equivalent to running "onos $OC1".
"onos-log 2" is equivalent to "onos-log $OC2".

If the argument is not a number there should be no change to the behaviour
of the script (original invocations should still work as expected).

Will make this change for other commands in the future if there are no issues.

Change-Id: I7621cce9076c088d3bcb1aa4d6c8f8f8525823ca
1 +#!/bin/bash
2 +
3 +validate_number () {
4 + local re="^[0-9]+$"
5 + if [[ ! $1 =~ $re ]] ; then
6 + return 1
7 + fi
8 +
9 + return 0
10 +}
11 +
12 +find_node () {
13 + if validate_number $1 ; then
14 + # input is a number, try to find if an OC node is defined
15 +
16 + oc_try="OC$1"
17 + node=${!oc_try}
18 +
19 + if [ -n "$node" ]; then
20 + # node lookup succeeded, return node
21 + echo $node
22 + else
23 + # node lookup failed, return original input
24 + echo $1
25 + fi
26 +
27 + else
28 + echo $1
29 + fi
30 +
31 + return 0
32 +}
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
5 5
6 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 6 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7 . $ONOS_ROOT/tools/build/envDefaults 7 . $ONOS_ROOT/tools/build/envDefaults
8 +. $ONOS_ROOT/tools/test/bin/find-node.sh
8 9
9 [ "$1" = "-w" ] && shift && onos-wait-for-start $1 10 [ "$1" = "-w" ] && shift && onos-wait-for-start $1
10 11
11 -[ -n "$1" ] && OCI=$1 && shift 12 +[ -n "$1" ] && OCI=$(find_node $1) && shift
12 client -h $OCI -u karaf "$@" 2>/dev/null 13 client -h $OCI -u karaf "$@" 2>/dev/null
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
5 5
6 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 6 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
7 . $ONOS_ROOT/tools/build/envDefaults 7 . $ONOS_ROOT/tools/build/envDefaults
8 +. $ONOS_ROOT/tools/test/bin/find-node.sh
8 9
9 less=0 10 less=0
10 -
11 [ "$1" = "-l" ] && shift && less=1 11 [ "$1" = "-l" ] && shift && less=1
12 12
13 -remote=$ONOS_USER@${1:-$OCI} 13 +remote=$(find_node $1)
14 +
15 +remote=$ONOS_USER@${remote:-$OCI}
14 instance=$2 16 instance=$2
15 17
16 [ -n "$instance" ] && \ 18 [ -n "$instance" ] && \
......