blob: e677873c3a553aa508f1c2039b84e1e0a7ab53fb [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# -----------------------------------------------------------------------------
Thomas Vachuska15370d22018-01-30 13:57:38 -08005function usage() {
6 echo "usage: $(basename $0)[-x] [-u user] [-p password] [-s partitionSize] ip1 ip2..." && exit 1
7}
Thomas Vachuska82e60a92015-04-30 01:15:58 -07008
Thomas Vachuska3c831fa2015-08-17 18:44:15 -07009# Scan arguments for user/password or other options...
Thiago Santos7a174cf2016-09-01 14:56:54 -030010while getopts u:p:s: o; do
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070011 case "$o" in
12 u) user=$OPTARG;;
13 p) password=$OPTARG;;
Thiago Santos7a174cf2016-09-01 14:56:54 -030014 s) partitionsize=$OPTARG;;
Thomas Vachuska15370d22018-01-30 13:57:38 -080015 *) usage;;
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070016 esac
17done
Phil Huang5f9603d2016-01-21 01:01:09 +080018ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
19ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
20user=${user:-$ONOS_WEB_USER}
21password=${password:-$ONOS_WEB_PASS}
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070022let OPC=$OPTIND-1
23shift $OPC
24
Thomas Vachuska15370d22018-01-30 13:57:38 -080025[ $# -lt 2 ] && usage
26
Thomas Vachuska82e60a92015-04-30 01:15:58 -070027ip=$1
28shift
29nodes=$*
30
31ipPrefix=${ip%.*}
32
33aux=/tmp/${ipPrefix}.cluster.json
34trap "rm -f $aux" EXIT
35
36echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
37for node in $nodes; do
38 echo ", { \"ip\": \"$node\" }" >> $aux
39done
Thiago Santos7a174cf2016-09-01 14:56:54 -030040echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux
41if ! [ -z ${partitionsize} ]; then
42 echo ", \"partitionSize\": $partitionsize" >> $aux
43fi
44echo " }" >> $aux
Thomas Vachuska82e60a92015-04-30 01:15:58 -070045
46for node in $ip $nodes; do
47 echo "Forming cluster on $node..."
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070048 curl --user $user:$password -X POST \
49 http://$node:8181/onos/v1/cluster/configuration -d @$aux
Phil Huang5f9603d2016-01-21 01:01:09 +080050done