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