Thomas Vachuska | 1627dc8 | 2015-11-13 12:22:14 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # ONOS network configuration uploader. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | . $ONOS_ROOT/tools/build/envDefaults |
Jonathan Hart | c86b00e | 2016-02-17 22:31:50 -0800 | [diff] [blame] | 8 | . $ONOS_ROOT/tools/test/bin/find-node.sh |
Thomas Vachuska | 1627dc8 | 2015-11-13 12:22:14 -0800 | [diff] [blame] | 9 | |
Jonathan Hart | c86b00e | 2016-02-17 22:31:50 -0800 | [diff] [blame] | 10 | fail="--fail" |
| 11 | [ "$1" == "-v" ] && shift && fail="" |
| 12 | |
| 13 | node=$(find_node $1) |
Thomas Vachuska | 1627dc8 | 2015-11-13 12:22:14 -0800 | [diff] [blame] | 14 | file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}" |
| 15 | url="${3}" |
| 16 | |
Jonathan Hart | c86b00e | 2016-02-17 22:31:50 -0800 | [diff] [blame] | 17 | method="POST" |
Phil Huang | 5805075 | 2016-06-25 01:22:23 +0800 | [diff] [blame^] | 18 | [ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE" |
Jonathan Hart | c86b00e | 2016-02-17 22:31:50 -0800 | [diff] [blame] | 19 | |
Phil Huang | 465a9b8 | 2016-06-23 23:33:40 +0800 | [diff] [blame] | 20 | if [ $method == "POST" ]; then |
Phil Huang | 5805075 | 2016-06-25 01:22:23 +0800 | [diff] [blame^] | 21 | # Validate JSON |
| 22 | cat $file | python -m json.tool >> /dev/null |
| 23 | if [ "$?" -ne "0" ]; then |
| 24 | echo "Not valid JSON File" && exit 1 |
| 25 | fi |
| 26 | curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ |
| 27 | -X POST -H 'Content-Type:application/json' \ |
| 28 | http://$node:8181/onos/v1/network/configuration/${url} -d@$file |
| 29 | elif [ $method == "DELETE" ]; then |
| 30 | curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ |
| 31 | -X DELETE http://$node:8181/onos/v1/network/configuration/${url} |
Phil Huang | 465a9b8 | 2016-06-23 23:33:40 +0800 | [diff] [blame] | 32 | fi |