blob: 5e2283620f10e2134c8609ae9ac95e6e0216f83b [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
Thomas Vachuskabee8a912018-02-28 10:02:16 -080023ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
Ray Milkey5c0d8f92017-06-09 12:26:31 -070024ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
25
Thomas Vachuskabee8a912018-02-28 10:02:16 -080026. $(dirname $0)/_find-node
27. $(dirname $0)/_check-json
Ray Milkey5c0d8f92017-06-09 12:26:31 -070028
29fail="--fail"
30[ "$1" == "-v" ] && shift && fail=""
31
32node=$(find_node $1)
33file="${2}"
34url="${3}"
35
36if [ "$node" == "" -o "$file" == "" ]; then
37 echo "Usage: onos-netcfg [-v] node file|DELETE [url]"
38 exit 1
39fi
40
41method="POST"
42[ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE"
43
44if [ $method == "POST" ]; then
Ray Milkeya67943d2017-06-15 10:04:48 -070045 checkJson $file
Ray Milkey5c0d8f92017-06-09 12:26:31 -070046 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
47 -X POST -H 'Content-Type:application/json' \
48 http://$node:8181/onos/v1/network/configuration/${url} -d@$file
49elif [ $method == "DELETE" ]; then
50 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
51 -X DELETE http://$node:8181/onos/v1/network/configuration/${url}
52fi