Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 2 | |
| 3 | # |
| 4 | # Copyright 2015-present Open Networking Foundation |
| 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 | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 19 | # ----------------------------------------------------------------------------- |
| 20 | # Forms ONOS cluster using REST API of each separate instance. |
| 21 | # ----------------------------------------------------------------------------- |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 22 | function usage() { |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 23 | echo "usage: $(basename $0)[-x] [-P port] [-u user] [-p password] [-s partitionSize] ip1 ip2..." && exit 1 |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 24 | } |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 25 | |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 26 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 27 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 28 | ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181' |
| 29 | |
| 30 | port=${ONOS_WEB_PORT} |
| 31 | user=${ONOS_WEB_USER} |
| 32 | password=${ONOS_WEB_PASS} |
| 33 | |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 34 | # Scan arguments for user/password or other options... |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 35 | while getopts P:u:p:s: o; do |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 36 | case "$o" in |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 37 | P) port=$OPTARG;; |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 38 | u) user=$OPTARG;; |
| 39 | p) password=$OPTARG;; |
Thiago Santos | 7a174cf | 2016-09-01 14:56:54 -0300 | [diff] [blame] | 40 | s) partitionsize=$OPTARG;; |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 41 | *) usage;; |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 42 | esac |
| 43 | done |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 44 | |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 45 | let OPC=$OPTIND-1 |
| 46 | shift $OPC |
| 47 | |
Thomas Vachuska | 15370d2 | 2018-01-30 13:57:38 -0800 | [diff] [blame] | 48 | [ $# -lt 2 ] && usage |
| 49 | |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 50 | ip=$1 |
| 51 | shift |
| 52 | nodes=$* |
| 53 | |
| 54 | ipPrefix=${ip%.*} |
| 55 | |
| 56 | aux=/tmp/${ipPrefix}.cluster.json |
| 57 | trap "rm -f $aux" EXIT |
| 58 | |
| 59 | echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux |
| 60 | for node in $nodes; do |
| 61 | echo ", { \"ip\": \"$node\" }" >> $aux |
| 62 | done |
Thiago Santos | 7a174cf | 2016-09-01 14:56:54 -0300 | [diff] [blame] | 63 | echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux |
| 64 | if ! [ -z ${partitionsize} ]; then |
| 65 | echo ", \"partitionSize\": $partitionsize" >> $aux |
| 66 | fi |
| 67 | echo " }" >> $aux |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 68 | |
| 69 | for node in $ip $nodes; do |
| 70 | echo "Forming cluster on $node..." |
Thomas Vachuska | 4bd4bf1 | 2018-04-16 14:02:18 -0700 | [diff] [blame] | 71 | curl --fail -sSL --user $user:$password -X POST \ |
| 72 | http://$node:$port/onos/v1/cluster/configuration -d @$aux |
Phil Huang | 5f9603d | 2016-01-21 01:01:09 +0800 | [diff] [blame] | 73 | done |