blob: 4d5441dc37e91cce8677e89a59123941e9fa20b9 [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# -----------------------------------------------------------------------------
Thomas Vachuska4bd4bf12018-04-16 14:02:18 -070022function usage {
23 echo "usage: onos-app [options] <node-ip> list" >&2
24 echo " onos-app [options] <node-ip> {install|install!} <app-file>" >&2
25 echo " onos-app [options] <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
26 echo " onos-app [options] <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
27 echo ""
28 echo "options: [-P port] [-u user] [-p password] [-v]"
29 exit 1
30}
Thomas Vachuska02aeb032015-01-06 22:36:30 -080031
Thomas Vachuska4bd4bf12018-04-16 14:02:18 -070032. $(dirname $0)/_rest-port
Thomas Vachuska7f2a3562018-02-28 10:02:16 -080033. $(dirname $0)/_find-node
Ray Milkey5c0d8f92017-06-09 12:26:31 -070034
35node=$(find_node $1)
Thomas Vachuska02aeb032015-01-06 22:36:30 -080036cmd=${2:-list}
37app=${3}
38
Thomas Vachuska4bd4bf12018-04-16 14:02:18 -070039export URL=http://$node:$port/onos/v1/applications
Thomas Vachuska02aeb032015-01-06 22:36:30 -080040export HDR="-HContent-Type:application/octet-stream"
alshabib20a070b2016-06-03 14:44:05 -070041export HAJ="-HContent-Type:application/json"
Thomas Vachuska4bd4bf12018-04-16 14:02:18 -070042export curl="curl $fail -sSL --user $user:$password --noproxy ${node} "
Thomas Vachuska02aeb032015-01-06 22:36:30 -080043
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070044
Thomas Vachuska6723a482015-05-01 13:13:23 -070045# Extract app name from the specified *.oar file
46function appName {
47 aux=/tmp/aux$$.jar
48 cp $1 $aux
49 pushd /tmp >/dev/null
50 jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2
51 rm -f $aux /tmp/app.xml
52 popd >/dev/null
53}
54
Thomas Vachuska94117802015-04-17 10:27:18 -070055[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
56
Thomas Vachuska02aeb032015-01-06 22:36:30 -080057case $cmd in
58 list) $curl -X GET $URL;;
alshabib20a070b2016-06-03 14:44:05 -070059 installUrl!|installUrl)
60 activate="false"
61 [ $cmd = "installUrl!" ] && activate="true"
62 [ $# -lt 3 ] && usage
63 appurl=$3
64 $curl -X POST $HAJ -d '{"url" : "'"$appurl"'", "activate" : "'$activate'" }' $URL
65 ;;
Thomas Vachuska6723a482015-05-01 13:13:23 -070066 install!|install)
67 [ $cmd = "install!" ] && activate="?activate=true"
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070068 [ $# -lt 3 -o ! -f $app ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070069 $curl -X POST $HDR $URL$activate --data-binary @$app
70 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070071
Thomas Vachuska6723a482015-05-01 13:13:23 -070072 reinstall!|reinstall)
73 [ $cmd = "reinstall!" ] && activate="?activate=true"
74 [ $# -lt 4 -a ! -f "$3" ] && usage
75 [ $# -eq 4 -a ! -f "$4" ] && usage
76 oar=$4
77 [ $# -lt 4 ] && oar=$3 && app=$(appName $oar)
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070078 $curl -X DELETE $URL/$app
Thomas Vachuska6723a482015-05-01 13:13:23 -070079 $curl -X POST $HDR $URL$activate --data-binary @$oar
80 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070081
82 uninstall)
83 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070084 $curl -X DELETE $URL/$app
85 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070086 activate)
87 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070088 $curl -X POST $URL/$app/active
89 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070090 deactivate)
91 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070092 $curl -X DELETE $URL/$app/active
93 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070094
95 *) usage;;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080096esac
Brian O'Connor3938f612015-04-14 15:01:32 -070097
Thomas Vachuska16501b02015-08-24 16:58:32 -070098
99status=$?
Thomas Vachuska94117802015-04-17 10:27:18 -0700100echo # new line for prompt
Thomas Vachuska16501b02015-08-24 16:58:32 -0700101exit $status