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 |
| 15 | user=${user:-onos} # user defaults to 'onos' |
| 16 | password=${password:-$user} # password defaults to user name if not specified |
| 17 | let OPC=$OPTIND-1 |
| 18 | shift $OPC |
| 19 | |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 20 | ip=$1 |
| 21 | shift |
| 22 | nodes=$* |
| 23 | |
| 24 | ipPrefix=${ip%.*} |
| 25 | |
| 26 | aux=/tmp/${ipPrefix}.cluster.json |
| 27 | trap "rm -f $aux" EXIT |
| 28 | |
| 29 | echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux |
| 30 | for node in $nodes; do |
| 31 | echo ", { \"ip\": \"$node\" }" >> $aux |
| 32 | done |
| 33 | echo "], \"ipPrefix\": \"$ipPrefix.*\" }" >> $aux |
| 34 | |
| 35 | for node in $ip $nodes; do |
| 36 | echo "Forming cluster on $node..." |
Thomas Vachuska | 3c831fa | 2015-08-17 18:44:15 -0700 | [diff] [blame^] | 37 | curl --user $user:$password -X POST \ |
| 38 | http://$node:8181/onos/v1/cluster/configuration -d @$aux |
Thomas Vachuska | 82e60a9 | 2015-04-30 01:15:58 -0700 | [diff] [blame] | 39 | done |