blob: 4e3645c623787714d344e7ebca6501bc651b0b4d [file] [log] [blame]
Thomas Vachuska82e60a92015-04-30 01:15:58 -07001#!/bin/bash
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -07002
3#
4# Copyright 2015-present Open Networking Foundation
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
Thomas Vachuska82e60a92015-04-30 01:15:58 -070019# -----------------------------------------------------------------------------
20# Forms ONOS cluster using REST API of each separate instance.
21# -----------------------------------------------------------------------------
Thomas Vachuska15370d22018-01-30 13:57:38 -080022function usage() {
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070023 echo "usage: $(basename $0)[-x] [-P port] [-u user] [-p password] [-s partitionSize] ip1 ip2..." && exit 1
Thomas Vachuska15370d22018-01-30 13:57:38 -080024}
Thomas Vachuska82e60a92015-04-30 01:15:58 -070025
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070026ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
27ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
28ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181'
29
30port=${ONOS_WEB_PORT}
31user=${ONOS_WEB_USER}
32password=${ONOS_WEB_PASS}
33
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070034# Scan arguments for user/password or other options...
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070035while getopts P:u:p:s: o; do
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070036 case "$o" in
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070037 P) port=$OPTARG;;
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070038 u) user=$OPTARG;;
39 p) password=$OPTARG;;
Thiago Santos7a174cf2016-09-01 14:56:54 -030040 s) partitionsize=$OPTARG;;
Thomas Vachuska15370d22018-01-30 13:57:38 -080041 *) usage;;
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070042 esac
43done
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070044
Thomas Vachuska3c831fa2015-08-17 18:44:15 -070045let OPC=$OPTIND-1
46shift $OPC
47
Thomas Vachuska15370d22018-01-30 13:57:38 -080048[ $# -lt 2 ] && usage
49
Thomas Vachuska82e60a92015-04-30 01:15:58 -070050ip=$1
51shift
52nodes=$*
53
54ipPrefix=${ip%.*}
55
56aux=/tmp/${ipPrefix}.cluster.json
57trap "rm -f $aux" EXIT
58
59echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
60for node in $nodes; do
61 echo ", { \"ip\": \"$node\" }" >> $aux
62done
Thiago Santos7a174cf2016-09-01 14:56:54 -030063echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux
64if ! [ -z ${partitionsize} ]; then
65 echo ", \"partitionSize\": $partitionsize" >> $aux
66fi
67echo " }" >> $aux
Thomas Vachuska82e60a92015-04-30 01:15:58 -070068
69for node in $ip $nodes; do
70 echo "Forming cluster on $node..."
Thomas Vachuskaa7be50d2018-04-16 14:02:18 -070071 curl --fail -sSL --user $user:$password -X POST \
72 http://$node:$port/onos/v1/cluster/configuration -d @$aux
Phil Huang5f9603d2016-01-21 01:01:09 +080073done