blob: fcb81ba7c7377d984d576adf9cd8495caa490368 [file] [log] [blame]
Boyuan Yan1c27bc72019-02-15 19:22:19 +00001#!/bin/bash
2
3# Create onos and atomix containers from related images.
4
5# Initialize the environment
6shopt -s expand_aliases
7export PATH="$PATH:$HOME/bin:onos/bin"
8export ONOS_ROOT=~/onos
9source ${ONOS_ROOT}/tools/dev/bash_profile
10KARAF_VERSION=`cat ${ONOS_ROOT}/tools/build/envDefaults | grep KARAF_VERSION= | awk -F '=' '{print $2}'`
11
12# Start ONOS cluster through docker
13cd ~/onos/tools/tutorials/vm
14SSH_KEY=$(cut -d\ -f2 ~/.ssh/id_rsa.pub)
15FULL_SSH_KEY=$(cat ~/.ssh/id_rsa.pub)
16echo "The public key in local host is: $SSH_KEY"
17
18# Create Atomix cluster using Atomix docker image
pierventrecdcd91c2021-05-06 09:27:00 +020019ATOMIX_IMAGE=atomix/atomix:3.1.12
Boyuan Yan1c27bc72019-02-15 19:22:19 +000020for i in {1..3}; do
21 echo "Setting up atomix-$i..."
22 docker container run --detach --name atomix-$i --hostname atomix-$i \
23 --restart=always -v /home/sdn/onos/tools/tutorials/vm/config:/atomix/config $ATOMIX_IMAGE \
24 --config /atomix/config/atomix-$i.conf
25done
26wait
27
28# Create and start ONOS cluster using ONOS docker image
29ONOS_IMAGE=onos:latest
30for i in {1..3}; do
31 echo "Setting up onos-$i..."
32 docker container run --detach --name onos-$i --hostname onos-$i --restart=always $ONOS_IMAGE
33 docker exec -i onos-$i /bin/bash -c "mkdir config; cat > config/cluster.json" < $ONOS_ROOT/tools/tutorials/vm/config/cluster-$i.json
34 docker exec -i onos-$i /bin/bash -c "touch /root/onos/apache-karaf-${KARAF_VERSION}/etc/keys.properties"
35 docker exec -i onos-$i /bin/bash -c "echo 'sdn=$SSH_KEY,_g_:admingroup' >> /root/onos/apache-karaf-${KARAF_VERSION}/etc/keys.properties"
36 docker exec -i onos-$i /bin/bash -c "/root/onos/bin/onos-user-password onos rocks"
37 docker exec -i onos-$i /bin/bash -c "ssh-keygen -f /root/.ssh/id_rsa -t rsa -N ''"
38 docker exec -i onos-$i /bin/bash -c "/etc/init.d/ssh start"
39 docker exec -i onos-$i /bin/bash -c "echo '$FULL_SSH_KEY' >> /root/.ssh/authorized_keys"
40done
41
42# Start onos and atomix docker containers
43function waitForStart {
44 sleep 5
45 for i in {1..3}; do
46 echo "Waiting for onos-$i startup..."
47 ip=$(docker container inspect onos-$i | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ')
48 echo "IP is: $ip"
49 for t in {1..60}; do
50 echo "$t-th times curl request"
51 curl --fail -sS http://$ip:8181/onos/v1/applications --user "onos:rocks" 1>/dev/null 2>&1 && break;
52 sleep 1;
53 done
54 echo
55 onos $ip summary >/dev/null 2>&1
56 done
57}
58
59# Extract the IP addresses of the ONOS nodes
60export OC1=$(docker container inspect onos-1 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ')
61export OC2=$(docker container inspect onos-2 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ')
62export OC3=$(docker container inspect onos-3 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ')
63export ONOS_INSTANCES="\"$OC1 $OC2 $OC3\""
64
65waitForStart
66
67# remove known hosts
68ssh-keygen -R $OC1
69ssh-keygen -R $OC2
70ssh-keygen -R $OC3
71# add to known-hosts list
72ssh-keyscan $OC1 >> ~/.ssh/known_hosts
73ssh-keyscan $OC2 >> ~/.ssh/known_hosts
74ssh-keyscan $OC3 >> ~/.ssh/known_hosts
75
76echo "#!/bin/bash" > /tmp/odtn/OCvar.sh
77echo "export OC1=$OC1" >> /tmp/odtn/OCvar.sh
78echo "export OC2=$OC2" >> /tmp/odtn/OCvar.sh
79echo "export OC3=$OC3" >> /tmp/odtn/OCvar.sh
80echo "export OCI=$OC1" >> /tmp/odtn/OCvar.sh
81echo "export ONOS_INSTANCES=$ONOS_INSTANCES" >> /tmp/odtn/OCvar.sh
82echo "export ONOS_USER=root" >> /tmp/odtn/OCvar.sh
83echo "export ONOS_INSTALL_DIR=/root/onos/apache-karaf-${KARAF_VERSION}/data" >> /tmp/odtn/OCvar.sh
84# sleep to wait onos instances start up
85sleep 20