Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Tool to manage ONOS applications using REST API. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | node=${1:-$OCI} |
| 7 | cmd=${2:-list} |
| 8 | app=${3} |
| 9 | |
| 10 | export URL=http://$node:8181/onos/v1/applications |
| 11 | export HDR="-HContent-Type:application/octet-stream" |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 12 | export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS" |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 13 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 14 | # Prints usage help |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 15 | function usage { |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 16 | echo "usage: onos-app <node-ip> list" >&2 |
| 17 | echo " onos-app <node-ip> {install|install!} <app-file>" >&2 |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 18 | echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2 |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 19 | echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2 |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 20 | exit 1 |
| 21 | } |
| 22 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 23 | # Extract app name from the specified *.oar file |
| 24 | function 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 Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 33 | [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage |
| 34 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 35 | case $cmd in |
| 36 | list) $curl -X GET $URL;; |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 37 | install!|install) |
| 38 | [ $cmd = "install!" ] && activate="?activate=true" |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 39 | [ $# -lt 3 -o ! -f $app ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 40 | $curl -X POST $HDR $URL$activate --data-binary @$app |
| 41 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 42 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 43 | 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 Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 49 | $curl -X DELETE $URL/$app |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 50 | $curl -X POST $HDR $URL$activate --data-binary @$oar |
| 51 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 52 | |
| 53 | uninstall) |
| 54 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 55 | $curl -X DELETE $URL/$app |
| 56 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 57 | activate) |
| 58 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 59 | $curl -X POST $URL/$app/active |
| 60 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 61 | deactivate) |
| 62 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 63 | $curl -X DELETE $URL/$app/active |
| 64 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 65 | |
| 66 | *) usage;; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 67 | esac |
Brian O'Connor | 3938f61 | 2015-04-14 15:01:32 -0700 | [diff] [blame] | 68 | |
Thomas Vachuska | 16501b0 | 2015-08-24 16:58:32 -0700 | [diff] [blame] | 69 | |
| 70 | status=$? |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 71 | echo # new line for prompt |
Thomas Vachuska | 16501b0 | 2015-08-24 16:58:32 -0700 | [diff] [blame] | 72 | exit $status |