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