blob: fe19d8e314569164728fb7bd59ba8d9f4ac4f1cd [file] [log] [blame]
Ray Milkey5c0d8f92017-06-09 12:26:31 -07001#!/bin/bash
2
3#
4# Copyright 2015-present Open Networking Laboratory
5#
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
31
32fail="--fail"
33[ "$1" == "-v" ] && shift && fail=""
34
35node=$(find_node $1)
36file="${2}"
37url="${3}"
38
39if [ "$node" == "" -o "$file" == "" ]; then
40 echo "Usage: onos-netcfg [-v] node file|DELETE [url]"
41 exit 1
42fi
43
44method="POST"
45[ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE"
46
47if [ $method == "POST" ]; then
48 # Validate JSON
49 cat $file | python -m json.tool >> /dev/null
50 if [ "$?" -ne "0" ]; then
51 echo "Not valid JSON File" && exit 1
52 fi
53 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
54 -X POST -H 'Content-Type:application/json' \
55 http://$node:8181/onos/v1/network/configuration/${url} -d@$file
56elif [ $method == "DELETE" ]; then
57 curl $fail -sSL --user $ONOS_WEB_USER:$ONOS_WEB_PASS \
58 -X DELETE http://$node:8181/onos/v1/network/configuration/${url}
59fi