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... |
| 9 | while getopts u:p: o; do |
| 10 | case "$o" in |
| 11 | u) user=$OPTARG;; |
| 12 | p) password=$OPTARG;; |
| 13 | esac |
| 14 | done |
Phil Huang | 5f9603d | 2016-01-21 01:01:09 +0800 | [diff] [blame] | 15 | ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos' |
| 16 | ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks' |
| 17 | user=${user:-$ONOS_WEB_USER} |
| 18 | password=${password:-$ONOS_WEB_PASS} |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 19 | let OPC=$OPTIND-1 |
| 20 | shift $OPC |
| 21 | |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 22 | ip=$1 |
| 23 | shift |
| 24 | nodes=$* |
| 25 | |
| 26 | ipPrefix=${ip%.*} |
| 27 | |
| 28 | aux=/tmp/${ipPrefix}.cluster.json |
| 29 | trap "rm -f $aux" EXIT |
| 30 | |
| 31 | echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux |
| 32 | for node in $nodes; do |
| 33 | echo ", { \"ip\": \"$node\" }" >> $aux |
| 34 | done |
| 35 | echo "], \"ipPrefix\": \"$ipPrefix.*\" }" >> $aux |
| 36 | |
| 37 | for node in $ip $nodes; do |
| 38 | echo "Forming cluster on $node..." |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame] | 39 | curl --user $user:$password -X POST \ |
| 40 | http://$node:8181/onos/v1/cluster/configuration -d @$aux |
Phil Huang | 5f9603d | 2016-01-21 01:01:09 +0800 | [diff] [blame] | 41 | done |