blob: fb6fff6ce59be3fc302e4fc5c2788fe1bc63be94 [file] [log] [blame]
Zack Williams2b946292016-08-22 15:32:29 -07001#!/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"
12export HAJ="-HContent-Type:application/json"
13export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS"
14
15# Prints usage help
16function usage {
17 echo "usage: onos-app <node-ip> list" >&2
18 echo " onos-app <node-ip> {install|install!} <app-file>" >&2
19 echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2
20 echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2
21 exit 1
22}
23
24# 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
34[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage
35
36case $cmd in
37 list) $curl -X GET $URL;;
38 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 ;;
45 install!|install)
46 [ $cmd = "install!" ] && activate="?activate=true"
47 [ $# -lt 3 -o ! -f $app ] && usage
48 $curl -X POST $HDR $URL$activate --data-binary @$app
49 ;;
50
51 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)
57 $curl -X DELETE $URL/$app
58 $curl -X POST $HDR $URL$activate --data-binary @$oar
59 ;;
60
61 uninstall)
62 [ $# -lt 3 ] && usage
63 $curl -X DELETE $URL/$app
64 ;;
65 activate)
66 [ $# -lt 3 ] && usage
67 $curl -X POST $URL/$app/active
68 ;;
69 deactivate)
70 [ $# -lt 3 ] && usage
71 $curl -X DELETE $URL/$app/active
72 ;;
73
74 *) usage;;
75esac
76
77
78status=$?
79echo # new line for prompt
80exit $status