blob: 17552ac0a01497e5c5c9664e580d47b373f02b57 [file] [log] [blame]
Ray Milkey5c0d8f92017-06-09 12:26:31 -07001#!/bin/bash
2
3#
Brian O'Connora09fe5b2017-08-03 21:12:30 -07004# Copyright 2015-present Open Networking Foundation
Ray Milkey5c0d8f92017-06-09 12:26:31 -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# ONOS network configuration uploader.
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
30. ${ONOS_HOME}/bin/_find-node
Ray Milkeya67943d2017-06-15 10:04:48 -070031. ${ONOS_HOME}/bin/_check-json
Ray Milkey5c0d8f92017-06-09 12:26:31 -070032
33fail="--fail"
34[ "$1" == "-v" ] && shift && fail=""
35
36node=$(find_node $1)
37file="${2}"
38url="${3}"
39
40if [ "$node" == "" -o "$file" == "" ]; then
41 echo "Usage: onos-netcfg [-v] node file|DELETE [url]"
42 exit 1
43fi
44
45method="POST"
46[ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE"
47
48if [ $method == "POST" ]; then
Ray Milkeya67943d2017-06-15 10:04:48 -070049 checkJson $file
Ray Milkey5c0d8f92017-06-09 12:26:31 -070050 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
51 -X POST -H 'Content-Type:application/json' \
52 http://$node:8181/onos/v1/network/configuration/${url} -d@$file
53elif [ $method == "DELETE" ]; then
54 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
55 -X DELETE http://$node:8181/onos/v1/network/configuration/${url}
56fi