blob: 3ccf2a574620ad720e1e805f0b154a97c2897e22 [file] [log] [blame]
suibin zhangfd266fd2015-10-27 17:06:33 -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
8# 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
20ip=$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..."
37 curl --user $user:$password -X POST \
38 http://$node:8181/onos/v1/cluster/configuration -d @$aux
39done