blob: 08635decdb17a93e06ed57eb4460c45dc92cbd45 [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# -----------------------------------------------------------------------------
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070022function usage() {
23 echo "usage: onos-netcfg [-v] [-P port] [-u user] [-p password] node file|DELETE [url]"
24 exit 1
25}
Ray Milkey5c0d8f92017-06-09 12:26:31 -070026
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070027. $(dirname $0)/_rest-port
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080028. $(dirname $0)/_find-node
29. $(dirname $0)/_check-json
Ray Milkey5c0d8f92017-06-09 12:26:31 -070030
Ray Milkey5c0d8f92017-06-09 12:26:31 -070031node=$(find_node $1)
32file="${2}"
33url="${3}"
34
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070035export URL="http://$node:$port/onos/v1/network/configuration/${url}"
36export curl="curl ${fail} -sSL --user $user:$password --noproxy ${node} "
37
38[ "$node" == "" -o "$file" == "" ] && usage;
Ray Milkey5c0d8f92017-06-09 12:26:31 -070039
40method="POST"
41[ $(echo $file | awk '{print tolower($0)}') == "delete" ] && method="DELETE"
42
43if [ $method == "POST" ]; then
Ray Milkeya67943d2017-06-15 10:04:48 -070044 checkJson $file
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070045 $curl -X POST -H 'Content-Type:application/json' $URL -d@$file
Ray Milkey5c0d8f92017-06-09 12:26:31 -070046elif [ $method == "DELETE" ]; then
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070047 $curl -X DELETE $URL
Ray Milkey5c0d8f92017-06-09 12:26:31 -070048fi