blob: 7ea93a7271eb4035755f0dd30996df9c0df6ff00 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001#!/bin/bash
Ray Milkey5c0d8f92017-06-09 12:26:31 -07002
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
Thomas Vachuska02aeb032015-01-06 22:36:30 -080019# -----------------------------------------------------------------------------
20# Tool to manage ONOS applications using REST API.
21# -----------------------------------------------------------------------------
22
Thomas Vachuska7f2a3562018-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 Vachuska7f2a3562018-02-28 10:02:16 -080026. $(dirname $0)/_find-node
Ray Milkey5c0d8f92017-06-09 12:26:31 -070027
28node=$(find_node $1)
Thomas Vachuska02aeb032015-01-06 22:36:30 -080029cmd=${2:-list}
30app=${3}
31
32export URL=http://$node:8181/onos/v1/applications
33export HDR="-HContent-Type:application/octet-stream"
alshabib20a070b2016-06-03 14:44:05 -070034export HAJ="-HContent-Type:application/json"
jaegonkim1f5fbe52016-08-31 06:57:02 -070035export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost "
Thomas Vachuska02aeb032015-01-06 22:36:30 -080036
Thomas Vachuska6723a482015-05-01 13:13:23 -070037# Prints usage help
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070038function usage {
Thomas Vachuska94117802015-04-17 10:27:18 -070039 echo "usage: onos-app <node-ip> list" >&2
40 echo " onos-app <node-ip> {install|install!} <app-file>" >&2
Thomas Vachuska6723a482015-05-01 13:13:23 -070041 echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
Thomas Vachuska94117802015-04-17 10:27:18 -070042 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070043 exit 1
44}
45
Thomas Vachuska6723a482015-05-01 13:13:23 -070046# Extract app name from the specified *.oar file
47function appName {
48 aux=/tmp/aux$$.jar
49 cp $1 $aux
50 pushd /tmp >/dev/null
51 jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2
52 rm -f $aux /tmp/app.xml
53 popd >/dev/null
54}
55
Thomas Vachuska94117802015-04-17 10:27:18 -070056[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
57
Thomas Vachuska02aeb032015-01-06 22:36:30 -080058case $cmd in
59 list) $curl -X GET $URL;;
alshabib20a070b2016-06-03 14:44:05 -070060 installUrl!|installUrl)
61 activate="false"
62 [ $cmd = "installUrl!" ] && activate="true"
63 [ $# -lt 3 ] && usage
64 appurl=$3
65 $curl -X POST $HAJ -d '{"url" : "'"$appurl"'", "activate" : "'$activate'" }' $URL
66 ;;
Thomas Vachuska6723a482015-05-01 13:13:23 -070067 install!|install)
68 [ $cmd = "install!" ] && activate="?activate=true"
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070069 [ $# -lt 3 -o ! -f $app ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070070 $curl -X POST $HDR $URL$activate --data-binary @$app
71 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070072
Thomas Vachuska6723a482015-05-01 13:13:23 -070073 reinstall!|reinstall)
74 [ $cmd = "reinstall!" ] && activate="?activate=true"
75 [ $# -lt 4 -a ! -f "$3" ] && usage
76 [ $# -eq 4 -a ! -f "$4" ] && usage
77 oar=$4
78 [ $# -lt 4 ] && oar=$3 && app=$(appName $oar)
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070079 $curl -X DELETE $URL/$app
Thomas Vachuska6723a482015-05-01 13:13:23 -070080 $curl -X POST $HDR $URL$activate --data-binary @$oar
81 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070082
83 uninstall)
84 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070085 $curl -X DELETE $URL/$app
86 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070087 activate)
88 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070089 $curl -X POST $URL/$app/active
90 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070091 deactivate)
92 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070093 $curl -X DELETE $URL/$app/active
94 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070095
96 *) usage;;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080097esac
Brian O'Connor3938f612015-04-14 15:01:32 -070098
Thomas Vachuska16501b02015-08-24 16:58:32 -070099
100status=$?
Thomas Vachuska94117802015-04-17 10:27:18 -0700101echo # new line for prompt
Thomas Vachuska16501b02015-08-24 16:58:32 -0700102exit $status