A R Karthick | 2b93d6a | 2016-09-06 15:19:09 -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 | |
| 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 | 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} |
| 19 | let OPC=$OPTIND-1 |
| 20 | shift $OPC |
| 21 | |
| 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..." |
| 39 | curl --user $user:$password -X POST \ |
| 40 | http://$node:8181/onos/v1/cluster/configuration -d @$aux |
| 41 | done |