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 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 22 | function usage() { |
| 23 | echo "usage: onos-netcfg [-v] [-P port] [-u user] [-p password] node file|DELETE [url]" |
| 24 | exit 1 |
| 25 | } |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 27 | . $(dirname $0)/_rest-port |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 28 | . $(dirname $0)/_find-node |
| 29 | . $(dirname $0)/_check-json |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 30 | |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 31 | node=$(find_node $1) |
| 32 | file="${2}" |
| 33 | url="${3}" |
| 34 | |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 35 | export URL="http://$node:$port/onos/v1/network/configuration/${url}" |
| 36 | export curl="curl ${fail} -sSL --user $user:$password --noproxy ${node} " |
| 37 | |
| 38 | [ "$node" == "" -o "$file" == "" ] && usage; |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 39 | |
| 40 | method="POST" |
| 41 | [ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE" |
| 42 | |
| 43 | if [ $method == "POST" ]; then |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 44 | checkJson $file |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 45 | $curl -X POST -H 'Content-Type:application/json' $URL -d@$file |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 46 | elif [ $method == "DELETE" ]; then |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 47 | $curl -X DELETE $URL |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 48 | fi |