blob: 130fa3bc395f4d8ea97e451883e456d62f028abd [file] [log] [blame]
Lee Yongjae6dc7e4f2017-12-06 16:17:51 +09001#!/bin/bash
2
3#
4# Copyright 2017-present Open Networking Foundation
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# Tool to manage ONOS applications 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
30. ${ONOS_HOME}/bin/_find-node
31
32node=$(find_node ${1:-localhost})
33cmd=${2:-show}
34
35export URL=http://$node:8181/onos/v1/simplefabric/$cmd
36#export HDR="-HContent-Type:application/octet-stream"
37#export HAJ="-HContent-Type:application/json"
38export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost "
39
40# Prints usage help
41function usage {
42 echo "usage: onos-simplefabric <node-ip> status|show|intents|reactive-intents|refresh|flush" >&2
43 exit 1
44}
45
46[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
47
48case $cmd in
49 status) $curl -X GET $URL;;
50 show) $curl -X GET $URL;;
51 intents) $curl -X GET $URL;;
52 reactive-intents) $curl -X GET $URL;;
53 refresh) $curl -X PUT $URL;;
54 flush) $curl -X PUT $URL;;
55
56 *) usage;;
57esac
58
59
60status=$?
61echo # new line for prompt
62exit $status