blob: 9286d0ca58b0e0da673642190ab0f7de992e7e7a [file] [log] [blame]
Thomas Vachuska82e60a92015-04-30 01:15:58 -07001#!/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 Vachuska3c831fa2015-08-17 18:44:15 -07008# Scan arguments for user/password or other options...
Thiago Santos7a174cf2016-09-01 14:56:54 -03009while getopts u:p:s: o; do
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070010 case "$o" in
11 u) user=$OPTARG;;
12 p) password=$OPTARG;;
Thiago Santos7a174cf2016-09-01 14:56:54 -030013 s) partitionsize=$OPTARG;;
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070014 esac
15done
Phil Huang5f9603d2016-01-21 01:01:09 +080016ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
17ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
18user=${user:-$ONOS_WEB_USER}
19password=${password:-$ONOS_WEB_PASS}
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070020let OPC=$OPTIND-1
21shift $OPC
22
Thomas Vachuska82e60a92015-04-30 01:15:58 -070023ip=$1
24shift
25nodes=$*
26
27ipPrefix=${ip%.*}
28
29aux=/tmp/${ipPrefix}.cluster.json
30trap "rm -f $aux" EXIT
31
32echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
33for node in $nodes; do
34 echo ", { \"ip\": \"$node\" }" >> $aux
35done
Thiago Santos7a174cf2016-09-01 14:56:54 -030036echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux
37if ! [ -z ${partitionsize} ]; then
38 echo ", \"partitionSize\": $partitionsize" >> $aux
39fi
40echo " }" >> $aux
Thomas Vachuska82e60a92015-04-30 01:15:58 -070041
42for node in $ip $nodes; do
43 echo "Forming cluster on $node..."
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070044 curl --user $user:$password -X POST \
45 http://$node:8181/onos/v1/cluster/configuration -d @$aux
Phil Huang5f9603d2016-01-21 01:01:09 +080046done