Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Forms ONOS cluster using REST API of each separate instance. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ $# -lt 2 ] && echo "usage: $(basename $0) ip1 ip2..." && exit 1 |
| 7 | |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 8 | # Scan arguments for user/password or other options... |
Thiago Santos | 7a174cf | 2016-09-01 14:56:54 -0300 | [diff] [blame^] | 9 | while getopts u:p:s: o; do |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 10 | case "$o" in |
| 11 | u) user=$OPTARG;; |
| 12 | p) password=$OPTARG;; |
Thiago Santos | 7a174cf | 2016-09-01 14:56:54 -0300 | [diff] [blame^] | 13 | s) partitionsize=$OPTARG;; |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 14 | esac |
| 15 | done |
Phil Huang | 5f9603d | 2016-01-21 01:01:09 +0800 | [diff] [blame] | 16 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 17 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 18 | user=${user:-$ONOS_WEB_USER} |
| 19 | password=${password:-$ONOS_WEB_PASS} |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 20 | let OPC=$OPTIND-1 |
| 21 | shift $OPC |
| 22 | |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 23 | ip=$1 |
| 24 | shift |
| 25 | nodes=$* |
| 26 | |
| 27 | ipPrefix=${ip%.*} |
| 28 | |
| 29 | aux=/tmp/${ipPrefix}.cluster.json |
| 30 | trap "rm -f $aux" EXIT |
| 31 | |
| 32 | echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux |
| 33 | for node in $nodes; do |
| 34 | echo ", { \"ip\": \"$node\" }" >> $aux |
| 35 | done |
Thiago Santos | 7a174cf | 2016-09-01 14:56:54 -0300 | [diff] [blame^] | 36 | echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux |
| 37 | if ! [ -z ${partitionsize} ]; then |
| 38 | echo ", \"partitionSize\": $partitionsize" >> $aux |
| 39 | fi |
| 40 | echo " }" >> $aux |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 41 | |
| 42 | for node in $ip $nodes; do |
| 43 | echo "Forming cluster on $node..." |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 44 | curl --user $user:$password -X POST \ |
| 45 | http://$node:8181/onos/v1/cluster/configuration -d @$aux |
Phil Huang | 5f9603d | 2016-01-21 01:01:09 +0800 | [diff] [blame] | 46 | done |