blob: a308bbcfb57402410d11d18be624738e9b33de49 [file] [log] [blame]
Thomas Vachuska1627dc82015-11-13 12:22:14 -08001#!/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 Hartc86b00e2016-02-17 22:31:50 -08008. $ONOS_ROOT/tools/test/bin/find-node.sh
Thomas Vachuska1627dc82015-11-13 12:22:14 -08009
Jonathan Hartc86b00e2016-02-17 22:31:50 -080010fail="--fail"
11[ "$1" == "-v" ] && shift && fail=""
12
13node=$(find_node $1)
Thomas Vachuska1627dc82015-11-13 12:22:14 -080014file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}"
15url="${3}"
16
Jonathan Hartc86b00e2016-02-17 22:31:50 -080017method="POST"
Phil Huang58050752016-06-25 01:22:23 +080018[ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE"
Jonathan Hartc86b00e2016-02-17 22:31:50 -080019
Phil Huang465a9b82016-06-23 23:33:40 +080020if [ $method == "POST" ]; then
Phil Huang58050752016-06-25 01:22:23 +080021 # 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
29elif [ $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 Huang465a9b82016-06-23 23:33:40 +080032fi