blob: 6b02dfa364015a02d7c4674bbae9fb35f22a8e9b [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
23# If ONOS_HOME is set, respect its value.
24# If ONOS_HOME is not set (e.g. in the init or service environment),
25# set it based on this script's path.
26ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
27ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
28ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
29
30fail="--fail"
31[ "$1" == "-v" ] && shift && fail=""
32
33. ${ONOS_HOME}/bin/_find-node
34. ${ONOS_HOME}/bin/_check-json
35
36node=$(find_node $1)
37cmd=${2:-list}
38component=${3}
39file=${4}
40
41export URL=http://$node:8181/onos/v1/configuration/${component}
42export curl="curl ${fail} -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy ${node} "
43
44usage() {
45 echo "Usage: onos-cfg node [list|post|delete] component [JSON file if posting or deleting]"
46}
47
48if [ "$node" == "" -o "$component" == "" ]; then
49 usage && exit 1
50fi
51
52case $cmd in
53 list)
54 ${curl} -X GET ${URL} && echo;;
55 post|delete)
56 checkJson "$file"
57 $curl -X $cmd -H 'Content-Type:application/json' \
58 ${URL} -d@$file && echo;;
59 *) usage && exit 1;;
60esac
61
62
63
64
65
66