Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 2 | |
| 3 | # |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 4 | # Copyright 2015-present Open Networking Foundation |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 19 | # ----------------------------------------------------------------------------- |
| 20 | # Tool to manage ONOS applications using REST API. |
| 21 | # ----------------------------------------------------------------------------- |
| 22 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 23 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 24 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 25 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 26 | . $(dirname $0)/_find-node |
Ray Milkey | 5c0d8f9 | 2017-06-09 12:26:31 -0700 | [diff] [blame] | 27 | |
| 28 | node=$(find_node $1) |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 29 | cmd=${2:-list} |
| 30 | app=${3} |
| 31 | |
| 32 | export URL=http://$node:8181/onos/v1/applications |
| 33 | export HDR="-HContent-Type:application/octet-stream" |
alshabib | 20a070b | 2016-06-03 14:44:05 -0700 | [diff] [blame] | 34 | export HAJ="-HContent-Type:application/json" |
jaegonkim | 1f5fbe5 | 2016-08-31 06:57:02 -0700 | [diff] [blame] | 35 | export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS --noproxy localhost " |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 36 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 37 | # Prints usage help |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 38 | function usage { |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 39 | echo "usage: onos-app <node-ip> list" >&2 |
| 40 | echo " onos-app <node-ip> {install|install!} <app-file>" >&2 |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 41 | echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2 |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 42 | echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2 |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 43 | exit 1 |
| 44 | } |
| 45 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 46 | # Extract app name from the specified *.oar file |
| 47 | function appName { |
| 48 | aux=/tmp/aux$$.jar |
| 49 | cp $1 $aux |
| 50 | pushd /tmp >/dev/null |
| 51 | jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2 |
| 52 | rm -f $aux /tmp/app.xml |
| 53 | popd >/dev/null |
| 54 | } |
| 55 | |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 56 | [ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage |
| 57 | |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 58 | case $cmd in |
| 59 | list) $curl -X GET $URL;; |
alshabib | 20a070b | 2016-06-03 14:44:05 -0700 | [diff] [blame] | 60 | installUrl!|installUrl) |
| 61 | activate="false" |
| 62 | [ $cmd = "installUrl!" ] && activate="true" |
| 63 | [ $# -lt 3 ] && usage |
| 64 | appurl=$3 |
| 65 | $curl -X POST $HAJ -d '{"url" : "'"$appurl"'", "activate" : "'$activate'" }' $URL |
| 66 | ;; |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 67 | install!|install) |
| 68 | [ $cmd = "install!" ] && activate="?activate=true" |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 69 | [ $# -lt 3 -o ! -f $app ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 70 | $curl -X POST $HDR $URL$activate --data-binary @$app |
| 71 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 72 | |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 73 | reinstall!|reinstall) |
| 74 | [ $cmd = "reinstall!" ] && activate="?activate=true" |
| 75 | [ $# -lt 4 -a ! -f "$3" ] && usage |
| 76 | [ $# -eq 4 -a ! -f "$4" ] && usage |
| 77 | oar=$4 |
| 78 | [ $# -lt 4 ] && oar=$3 && app=$(appName $oar) |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 79 | $curl -X DELETE $URL/$app |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 80 | $curl -X POST $HDR $URL$activate --data-binary @$oar |
| 81 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 82 | |
| 83 | uninstall) |
| 84 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 85 | $curl -X DELETE $URL/$app |
| 86 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 87 | activate) |
| 88 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 89 | $curl -X POST $URL/$app/active |
| 90 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 91 | deactivate) |
| 92 | [ $# -lt 3 ] && usage |
Thomas Vachuska | 6723a48 | 2015-05-01 13:13:23 -0700 | [diff] [blame] | 93 | $curl -X DELETE $URL/$app/active |
| 94 | ;; |
Thomas Vachuska | c4cb100 | 2015-03-29 10:28:26 -0700 | [diff] [blame] | 95 | |
| 96 | *) usage;; |
Thomas Vachuska | 02aeb03 | 2015-01-06 22:36:30 -0800 | [diff] [blame] | 97 | esac |
Brian O'Connor | 3938f61 | 2015-04-14 15:01:32 -0700 | [diff] [blame] | 98 | |
Thomas Vachuska | 16501b0 | 2015-08-24 16:58:32 -0700 | [diff] [blame] | 99 | |
| 100 | status=$? |
Thomas Vachuska | 9411780 | 2015-04-17 10:27:18 -0700 | [diff] [blame] | 101 | echo # new line for prompt |
Thomas Vachuska | 16501b0 | 2015-08-24 16:58:32 -0700 | [diff] [blame] | 102 | exit $status |