blob: 578a443c9e8c878ae346c129f8eb9e62a8b262e2 [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
Phil Huang5f9603d2016-01-21 01:01:09 +080015ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
16ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
17user=${user:-$ONOS_WEB_USER}
18password=${password:-$ONOS_WEB_PASS}
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070019let OPC=$OPTIND-1
20shift $OPC
21
Thomas Vachuska82e60a92015-04-30 01:15:58 -070022ip=$1
23shift
24nodes=$*
25
26ipPrefix=${ip%.*}
27
28aux=/tmp/${ipPrefix}.cluster.json
29trap "rm -f $aux" EXIT
30
31echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
32for node in $nodes; do
33 echo ", { \"ip\": \"$node\" }" >> $aux
34done
35echo "], \"ipPrefix\": \"$ipPrefix.*\" }" >> $aux
36
37for node in $ip $nodes; do
38 echo "Forming cluster on $node..."
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070039 curl --user $user:$password -X POST \
40 http://$node:8181/onos/v1/cluster/configuration -d @$aux
Phil Huang5f9603d2016-01-21 01:01:09 +080041done