Ray Milkey | a67943d | 2017-06-15 10:04:48 -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 | a67943d | 2017-06-15 10:04:48 -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 | # Tool to manage ONOS component configurations using REST API. |
| 21 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 22 | usage() { |
| 23 | echo "usage: onos-cfg [-P port] [-u user] [-p password] [-v] \\" |
| 24 | echo " node [list|post|delete] component [JSON file if posting or deleting]" |
| 25 | } |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -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 |
| 30 | |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 31 | fail="--fail" |
| 32 | [ "$1" == "-v" ] && shift && fail="" |
| 33 | |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 34 | node=$(find_node $1) |
| 35 | cmd=${2:-list} |
| 36 | component=${3} |
| 37 | file=${4} |
| 38 | |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 39 | export URL=http://$node:$port/onos/v1/configuration/${component} |
| 40 | export curl="curl ${fail} -sSL --user $user:$password --noproxy ${node} " |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 41 | |
| 42 | if [ "$node" == "" -o "$component" == "" ]; then |
| 43 | usage && exit 1 |
| 44 | fi |
| 45 | |
| 46 | case $cmd in |
| 47 | list) |
| 48 | ${curl} -X GET ${URL} && echo;; |
| 49 | post|delete) |
| 50 | checkJson "$file" |
Thomas Vachuska | a7be50d | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 51 | $curl -X $cmd -H 'Content-Type:application/json' ${URL} -d@$file && echo;; |
Ray Milkey | a67943d | 2017-06-15 10:04:48 -0700 | [diff] [blame] | 52 | *) usage && exit 1;; |
| 53 | esac |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |