blob: 658a050bfb742b5813ddfe826b38bd9ab8145d38 [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"
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070012export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS"
Thomas Vachuska02aeb032015-01-06 22:36:30 -080013
Thomas Vachuska6723a482015-05-01 13:13:23 -070014# Prints usage help
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070015function usage {
Thomas Vachuska94117802015-04-17 10:27:18 -070016 echo "usage: onos-app <node-ip> list" >&2
17 echo " onos-app <node-ip> {install|install!} <app-file>" >&2
Thomas Vachuska6723a482015-05-01 13:13:23 -070018 echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
Thomas Vachuska94117802015-04-17 10:27:18 -070019 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070020 exit 1
21}
22
Thomas Vachuska6723a482015-05-01 13:13:23 -070023# Extract app name from the specified *.oar file
24function appName {
25 aux=/tmp/aux$$.jar
26 cp $1 $aux
27 pushd /tmp >/dev/null
28 jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2
29 rm -f $aux /tmp/app.xml
30 popd >/dev/null
31}
32
Thomas Vachuska94117802015-04-17 10:27:18 -070033[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
34
Thomas Vachuska02aeb032015-01-06 22:36:30 -080035case $cmd in
36 list) $curl -X GET $URL;;
Thomas Vachuska6723a482015-05-01 13:13:23 -070037 install!|install)
38 [ $cmd = "install!" ] && activate="?activate=true"
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070039 [ $# -lt 3 -o ! -f $app ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070040 $curl -X POST $HDR $URL$activate --data-binary @$app
41 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070042
Thomas Vachuska6723a482015-05-01 13:13:23 -070043 reinstall!|reinstall)
44 [ $cmd = "reinstall!" ] && activate="?activate=true"
45 [ $# -lt 4 -a ! -f "$3" ] && usage
46 [ $# -eq 4 -a ! -f "$4" ] && usage
47 oar=$4
48 [ $# -lt 4 ] && oar=$3 && app=$(appName $oar)
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070049 $curl -X DELETE $URL/$app
Thomas Vachuska6723a482015-05-01 13:13:23 -070050 $curl -X POST $HDR $URL$activate --data-binary @$oar
51 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070052
53 uninstall)
54 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070055 $curl -X DELETE $URL/$app
56 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070057 activate)
58 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070059 $curl -X POST $URL/$app/active
60 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070061 deactivate)
62 [ $# -lt 3 ] && usage
Thomas Vachuska6723a482015-05-01 13:13:23 -070063 $curl -X DELETE $URL/$app/active
64 ;;
Thomas Vachuskac4cb1002015-03-29 10:28:26 -070065
66 *) usage;;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080067esac
Brian O'Connor3938f612015-04-14 15:01:32 -070068
Thomas Vachuska94117802015-04-17 10:27:18 -070069echo # new line for prompt