Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Create onos and atomix containers from related images. |
| 4 | |
| 5 | # Initialize the environment |
| 6 | shopt -s expand_aliases |
| 7 | export PATH="$PATH:$HOME/bin:onos/bin" |
| 8 | export ONOS_ROOT=~/onos |
| 9 | source ${ONOS_ROOT}/tools/dev/bash_profile |
| 10 | KARAF_VERSION=`cat ${ONOS_ROOT}/tools/build/envDefaults | grep KARAF_VERSION= | awk -F '=' '{print $2}'` |
| 11 | |
| 12 | # Start ONOS cluster through docker |
| 13 | cd ~/onos/tools/tutorials/vm |
| 14 | SSH_KEY=$(cut -d\ -f2 ~/.ssh/id_rsa.pub) |
| 15 | FULL_SSH_KEY=$(cat ~/.ssh/id_rsa.pub) |
| 16 | echo "The public key in local host is: $SSH_KEY" |
| 17 | |
| 18 | # Create Atomix cluster using Atomix docker image |
pier | 7118551 | 2020-06-17 18:27:52 +0200 | [diff] [blame] | 19 | ATOMIX_IMAGE=atomix/atomix:3.1.9 |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 20 | for 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 |
| 25 | done |
| 26 | wait |
| 27 | |
| 28 | # Create and start ONOS cluster using ONOS docker image |
| 29 | ONOS_IMAGE=onos:latest |
| 30 | for 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" |
| 40 | done |
| 41 | |
| 42 | # Start onos and atomix docker containers |
| 43 | function 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 |
| 60 | export OC1=$(docker container inspect onos-1 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 61 | export OC2=$(docker container inspect onos-2 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 62 | export OC3=$(docker container inspect onos-3 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 63 | export ONOS_INSTANCES="\"$OC1 $OC2 $OC3\"" |
| 64 | |
| 65 | waitForStart |
| 66 | |
| 67 | # remove known hosts |
| 68 | ssh-keygen -R $OC1 |
| 69 | ssh-keygen -R $OC2 |
| 70 | ssh-keygen -R $OC3 |
| 71 | # add to known-hosts list |
| 72 | ssh-keyscan $OC1 >> ~/.ssh/known_hosts |
| 73 | ssh-keyscan $OC2 >> ~/.ssh/known_hosts |
| 74 | ssh-keyscan $OC3 >> ~/.ssh/known_hosts |
| 75 | |
| 76 | echo "#!/bin/bash" > /tmp/odtn/OCvar.sh |
| 77 | echo "export OC1=$OC1" >> /tmp/odtn/OCvar.sh |
| 78 | echo "export OC2=$OC2" >> /tmp/odtn/OCvar.sh |
| 79 | echo "export OC3=$OC3" >> /tmp/odtn/OCvar.sh |
| 80 | echo "export OCI=$OC1" >> /tmp/odtn/OCvar.sh |
| 81 | echo "export ONOS_INSTANCES=$ONOS_INSTANCES" >> /tmp/odtn/OCvar.sh |
| 82 | echo "export ONOS_USER=root" >> /tmp/odtn/OCvar.sh |
| 83 | echo "export ONOS_INSTALL_DIR=/root/onos/apache-karaf-${KARAF_VERSION}/data" >> /tmp/odtn/OCvar.sh |
| 84 | # sleep to wait onos instances start up |
| 85 | sleep 20 |