blob: d724f9675f7b35d082f76e5366befb4229a3e613 [file] [log] [blame]
Thomas Vachuska02aeb032015-01-06 22:36:30 -08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Tool to manage ONOS applications using REST API.
4# -----------------------------------------------------------------------------
5
6node=${1:-$OCI}
7cmd=${2:-list}
8app=${3}
9
10export URL=http://$node:8181/onos/v1/applications
11export HDR="-HContent-Type:application/octet-stream"
alshabib20a070b2016-06-03 14:44:05 -070012export HAJ="-HContent-Type:application/json"
jaegonkim1f5fbe52016-08-31 06:57:02 -070013export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost "
Thomas Vachuska02aeb032015-01-06 22:36:30 -080014
Thomas Vachuska6723a482015-05-01 13:13:23 -070015# Prints usage help
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070016function usage {
Thomas Vachuska94117802015-04-17 10:27:18 -070017 echo "usage: onos-app <node-ip> list" >&2
18 echo " onos-app <node-ip> {install|install!} <app-file>" >&2
Thomas Vachuska6723a482015-05-01 13:13:23 -070019 echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
Thomas Vachuska94117802015-04-17 10:27:18 -070020 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070021 exit 1
22}
23
Thomas Vachuska6723a482015-05-01 13:13:23 -070024# Extract app name from the specified *.oar file
25function appName {
26 aux=/tmp/aux$$.jar
27 cp $1 $aux
28 pushd /tmp >/dev/null
29 jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2
30 rm -f $aux /tmp/app.xml
31 popd >/dev/null
32}
33
Thomas Vachuska94117802015-04-17 10:27:18 -070034[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
35
Thomas Vachuska02aeb032015-01-06 22:36:30 -080036case $cmd in
37 list) $curl -X GET $URL;;
alshabib20a070b2016-06-03 14:44:05 -070038 installUrl!|installUrl)
39 activate="false"
40 [ $cmd = "installUrl!" ] && activate="true"
41 [ $# -lt 3 ] && usage
42 appurl=$3
43 $curl -X POST $HAJ -d '{"url" : "'"$appurl"'", "activate" : "'$activate'" }' $URL
44 ;;
Thomas Vachuska6723a482015-05-01 13:13:23 -070045 install!|install)
46 [ $cmd = "install!" ] && activate="?activate=true"
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070047 [ $# -lt 3 -o ! -f $app ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070048 $curl -X POST $HDR $URL$activate --data-binary @$app
49 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070050
Thomas Vachuska6723a482015-05-01 13:13:23 -070051 reinstall!|reinstall)
52 [ $cmd = "reinstall!" ] && activate="?activate=true"
53 [ $# -lt 4 -a ! -f "$3" ] && usage
54 [ $# -eq 4 -a ! -f "$4" ] && usage
55 oar=$4
56 [ $# -lt 4 ] && oar=$3 && app=$(appName $oar)
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070057 $curl -X DELETE $URL/$app
Thomas Vachuska6723a482015-05-01 13:13:23 -070058 $curl -X POST $HDR $URL$activate --data-binary @$oar
59 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070060
61 uninstall)
62 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070063 $curl -X DELETE $URL/$app
64 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070065 activate)
66 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070067 $curl -X POST $URL/$app/active
68 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070069 deactivate)
70 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070071 $curl -X DELETE $URL/$app/active
72 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070073
74 *) usage;;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080075esac
Brian O'Connor3938f612015-04-14 15:01:32 -070076
Thomas Vachuska16501b02015-08-24 16:58:32 -070077
78status=$?
Thomas Vachuska94117802015-04-17 10:27:18 -070079echo # new line for prompt
Thomas Vachuska16501b02015-08-24 16:58:32 -070080exit $status