blob: 6855d03f6e49b8aa0e843d8372b5d3639569a417 [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# -----------------------------------------------------------------------------
22
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080023ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
Ray Milkeya67943d2017-06-15 10:04:48 -070024ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
25
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080026. $(dirname $0)/_find-node
27. $(dirname $0)/_check-json
28
Ray Milkeya67943d2017-06-15 10:04:48 -070029fail="--fail"
30[ "$1" == "-v" ] && shift && fail=""
31
Ray Milkeya67943d2017-06-15 10:04:48 -070032node=$(find_node $1)
33cmd=${2:-list}
34component=${3}
35file=${4}
36
37export URL=http://$node:8181/onos/v1/configuration/${component}
38export curl="curl ${fail} -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy ${node} "
39
40usage() {
41 echo "Usage: onos-cfg node [list|post|delete] component [JSON file if posting or deleting]"
42}
43
44if [ "$node" == "" -o "$component" == "" ]; then
45 usage && exit 1
46fi
47
48case $cmd in
49 list)
50 ${curl} -X GET ${URL} && echo;;
51 post|delete)
52 checkJson "$file"
53 $curl -X $cmd -H 'Content-Type:application/json' \
54 ${URL} -d@$file && echo;;
55 *) usage && exit 1;;
56esac
57
58
59
60
61
62