blob: 7a0abda67e27ec9ba2a1a36d7fca8ff3f7d51407 [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...
9while getopts u:p: o; do
10 case "$o" in
11 u) user=$OPTARG;;
12 p) password=$OPTARG;;
13 esac
14done
15user=${user:-onos} # user defaults to 'onos'
16password=${password:-$user} # password defaults to user name if not specified
17let OPC=$OPTIND-1
18shift $OPC
19
Thomas Vachuska82e60a92015-04-30 01:15:58 -070020ip=$1
21shift
22nodes=$*
23
24ipPrefix=${ip%.*}
25
26aux=/tmp/${ipPrefix}.cluster.json
27trap "rm -f $aux" EXIT
28
29echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
30for node in $nodes; do
31 echo ", { \"ip\": \"$node\" }" >> $aux
32done
33echo "], \"ipPrefix\": \"$ipPrefix.*\" }" >> $aux
34
35for node in $ip $nodes; do
36 echo "Forming cluster on $node..."
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070037 curl --user $user:$password -X POST \
38 http://$node:8181/onos/v1/cluster/configuration -d @$aux
Thomas Vachuska82e60a92015-04-30 01:15:58 -070039done