blob: abb3be6017001674b6d653bdff532fcd696a2232 [file] [log] [blame]
Ray Milkeya67943d2017-06-15 10:04:48 -07001#!/bin/bash
2
3#
Brian O'Connora09fe5b2017-08-03 21:12:30 -07004# Copyright 2015-present Open Networking Foundation
Ray Milkeya67943d2017-06-15 10:04:48 -07005#
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 Vachuska1c188d32018-04-16 14:02:18 -070022usage() {
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 Milkeya67943d2017-06-15 10:04:48 -070026
Thomas Vachuska1c188d32018-04-16 14:02:18 -070027. $(dirname $0)/_rest-port
Thomas Vachuskabee8a912018-02-28 10:02:16 -080028. $(dirname $0)/_find-node
29. $(dirname $0)/_check-json
30
Ray Milkeya67943d2017-06-15 10:04:48 -070031fail="--fail"
32[ "$1" == "-v" ] && shift && fail=""
33
Ray Milkeya67943d2017-06-15 10:04:48 -070034node=$(find_node $1)
35cmd=${2:-list}
36component=${3}
37file=${4}
38
Thomas Vachuska1c188d32018-04-16 14:02:18 -070039export URL=http://$node:$port/onos/v1/configuration/${component}
40export curl="curl ${fail} -sSL --user $user:$password --noproxy ${node} "
Ray Milkeya67943d2017-06-15 10:04:48 -070041
42if [ "$node" == "" -o "$component" == "" ]; then
43 usage && exit 1
44fi
45
46case $cmd in
47 list)
48 ${curl} -X GET ${URL} && echo;;
49 post|delete)
50 checkJson "$file"
Thomas Vachuska1c188d32018-04-16 14:02:18 -070051 $curl -X $cmd -H 'Content-Type:application/json' ${URL} -d@$file && echo;;
Ray Milkeya67943d2017-06-15 10:04:48 -070052 *) usage && exit 1;;
53esac
54
55
56
57
58
59