Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 4 | # Copyright 2015-present Open Networking Foundation |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
| 19 | # ----------------------------------------------------------------------------- |
| 20 | # ONOS network configuration uploader. |
| 21 | # ----------------------------------------------------------------------------- |
| 22 | |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 23 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 24 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 25 | |
Thomas Vachuska | bee8a91 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 26 | . $(dirname $0)/_find-node |
| 27 | . $(dirname $0)/_check-json |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 28 | |
| 29 | fail="--fail" |
| 30 | [ "$1" == "-v" ] && shift && fail="" |
| 31 | |
| 32 | node=$(find_node $1) |
| 33 | file="${2}" |
| 34 | url="${3}" |
| 35 | |
| 36 | if [ "$node" == "" -o "$file" == "" ]; then |
| 37 | echo "Usage: onos-netcfg [-v] node file|DELETE [url]" |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | method="POST" |
| 42 | [ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE" |
| 43 | |
| 44 | if [ $method == "POST" ]; then |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 45 | checkJson $file |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 46 | curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ |
| 47 | -X POST -H 'Content-Type:application/json' \ |
| 48 | http://$node:8181/onos/v1/network/configuration/${url} -d@$file |
| 49 | elif [ $method == "DELETE" ]; then |
| 50 | curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ |
| 51 | -X DELETE http://$node:8181/onos/v1/network/configuration/${url} |
| 52 | fi |