sgovinda | cc73678 | 2017-05-02 20:06:37 +0530 | [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:s: o; do |
| 10 | case "$o" in |
| 11 | u) user=$OPTARG;; |
| 12 | p) password=$OPTARG;; |
| 13 | s) partitionsize=$OPTARG;; |
| 14 | esac |
| 15 | done |
| 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} |
| 20 | let OPC=$OPTIND-1 |
| 21 | shift $OPC |
| 22 | |
| 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 |
| 36 | echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux |
| 37 | if ! [ -z ${partitionsize} ]; then |
| 38 | echo ", \"partitionSize\": $partitionsize" >> $aux |
| 39 | fi |
| 40 | echo " }" >> $aux |
| 41 | |
| 42 | for node in $ip $nodes; do |
| 43 | echo "Forming cluster on $node..." |
| 44 | curl --user $user:$password -X POST \ |
| 45 | http://$node:8181/onos/v1/cluster/configuration -d @$aux |
| 46 | done |