blob: 4e3645c623787714d344e7ebca6501bc651b0b4d [file] [log] [blame]
#!/bin/bash
#
# Copyright 2015-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------------------------------------------------------------------
# Forms ONOS cluster using REST API of each separate instance.
# -----------------------------------------------------------------------------
function usage() {
echo "usage: $(basename $0)[-x] [-P port] [-u user] [-p password] [-s partitionSize] ip1 ip2..." && exit 1
}
ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
ONOS_WEB_PORT=${ONOS_WEB_PORT:-8181} # REST API port defaults to '8181'
port=${ONOS_WEB_PORT}
user=${ONOS_WEB_USER}
password=${ONOS_WEB_PASS}
# Scan arguments for user/password or other options...
while getopts P:u:p:s: o; do
case "$o" in
P) port=$OPTARG;;
u) user=$OPTARG;;
p) password=$OPTARG;;
s) partitionsize=$OPTARG;;
*) usage;;
esac
done
let OPC=$OPTIND-1
shift $OPC
[ $# -lt 2 ] && usage
ip=$1
shift
nodes=$*
ipPrefix=${ip%.*}
aux=/tmp/${ipPrefix}.cluster.json
trap "rm -f $aux" EXIT
echo "{ \"nodes\": [ { \"ip\": \"$ip\" }" > $aux
for node in $nodes; do
echo ", { \"ip\": \"$node\" }" >> $aux
done
echo "], \"ipPrefix\": \"$ipPrefix.*\"" >> $aux
if ! [ -z ${partitionsize} ]; then
echo ", \"partitionSize\": $partitionsize" >> $aux
fi
echo " }" >> $aux
for node in $ip $nodes; do
echo "Forming cluster on $node..."
curl --fail -sSL --user $user:$password -X POST \
http://$node:$port/onos/v1/cluster/configuration -d @$aux
done