Claudine Chiu | 0005a4d | 2016-05-25 12:13:43 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Checks vnet related entities (tenantId, networkId). |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
| 8 | |
Jon Hall | fb6009d | 2017-02-15 16:01:17 -0800 | [diff] [blame^] | 9 | aux=/tmp/stc/stc-$$.log |
Claudine Chiu | 0005a4d | 2016-05-25 12:13:43 -0400 | [diff] [blame] | 10 | trap "rm -f $aux 2>/dev/null" EXIT |
| 11 | target=${1:-$OCI} |
| 12 | command_name=`basename $0` |
| 13 | |
| 14 | # Prints usage help |
| 15 | function usage { |
| 16 | echo "usage: $command_name <node-ip> checkTenant <tenantId>" >&2 |
| 17 | echo " $command_name <node-ip> getNetworkId <tenantId>" >&2 |
| 18 | } |
| 19 | |
| 20 | # Extracts networkId |
| 21 | function extractAndPublishNetworkId() { |
| 22 | for token in $aString |
| 23 | do |
| 24 | if [[ $token =~ "networkId=" ]] |
| 25 | then |
| 26 | echo "@stc $token" |
| 27 | exit 0 |
| 28 | fi |
| 29 | done |
| 30 | return 1 |
| 31 | } |
| 32 | |
| 33 | echo $command_name: $* |
| 34 | [ $# -lt 3 ] || [ "$1" = "-h" ] && usage && exit 0 |
| 35 | |
| 36 | case "$2" in |
| 37 | "checkTenant") |
| 38 | onos $target "vnet-tenants" | tee $aux |
| 39 | grep -w $3 $aux && exit 0 |
| 40 | ;; |
| 41 | "getNetworkId") |
| 42 | onos $target "vnets" | tee $aux |
| 43 | aString=`grep "tenantId=$3," $aux | tail -1` #get last row |
| 44 | extractAndPublishNetworkId && exit 0 |
| 45 | ;; |
| 46 | *) |
| 47 | usage |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | cat $aux |
| 52 | exit 1 |
| 53 | |