blob: ad86718b57e88fa6d41355894d15f059028cd7ec [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 Vachuskaa7be50d2018-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 Vachuskaa7be50d2018-04-16 14:02:18 -070027. $(dirname $0)/_rest-port
Thomas Vachuska7f2a3562018-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 Vachuskaa7be50d2018-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"
Daniele Moro782e1542022-02-15 12:23:20 +010051 $curl -X $(echo ${cmd} | tr '[:lower:]' '[:upper:]') -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