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" |
| 12 | export curl="curl -sS" |
| 13 | |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 14 | function usage { |
| 15 | echo "usage: onos-app {install|install!} <app-file>" >&2 |
| 16 | echo " onos-app {reinstall|reinstall!} <app-name> <app-file>" >&2 |
| 17 | echo " onos-app {activate|deactivate|uninstall} <app-name>" >&2 |
| 18 | exit 1 |
| 19 | } |
| 20 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 21 | case $cmd in |
| 22 | list) $curl -X GET $URL;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 23 | install) |
| 24 | [ $# -lt 3 -o ! -f $app ] && usage |
| 25 | $curl -X POST $HDR $URL --data-binary @$app;; |
| 26 | install!) |
| 27 | [ $# -lt 3 -o ! -f $app ] && usage |
| 28 | $curl -X POST $HDR $URL?activate=true --data-binary @$app;; |
| 29 | |
| 30 | reinstall) |
| 31 | [ $# -lt 4 -o ! -f $4 ] && usage |
| 32 | $curl -X DELETE $URL/$app |
| 33 | $curl -X POST $HDR $URL --data-binary @$4;; |
| 34 | reinstall!) |
| 35 | [ $# -lt 4 -o ! -f $4 ] && usage |
| 36 | $curl -X DELETE $URL/$app |
| 37 | $curl -X POST $HDR $URL?activate=true --data-binary @$4;; |
| 38 | |
| 39 | uninstall) |
| 40 | [ $# -lt 3 ] && usage |
| 41 | $curl -X DELETE $URL/$app;; |
| 42 | activate) |
| 43 | [ $# -lt 3 ] && usage |
| 44 | $curl -X POST $URL/$app/active;; |
| 45 | deactivate) |
| 46 | [ $# -lt 3 ] && usage |
| 47 | $curl -X DELETE $URL/$app/active;; |
| 48 | |
| 49 | *) usage;; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 50 | esac |
Brian O'Connor | 3938f61 | 2015-04-14 15:01:32 -0700 | [diff] [blame] | 51 | |
| 52 | echo #new line for prompt |