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