Thomas Vachuska | c419f0e | 2018-02-07 14:24:46 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Creates the ONOS cluster using 3 docker container instances. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | export PATH="$PATH:bin:onos/bin" |
| 6 | |
| 7 | # Creates ONOS cluster using ONOS docker images |
| 8 | ONOS_IMAGE=onosproject/onos:1.12.0 |
| 9 | SSH_KEY=$(cut -d\ -f2 ~/.ssh/id_rsa.pub) |
| 10 | |
| 11 | for i in {1..3}; do |
| 12 | echo "Setting up onos-$i..." |
| 13 | docker container run --detach --name onos-$i --hostname onos-$i --restart always $ONOS_IMAGE |
| 14 | docker exec -i onos-$i /bin/bash -c "mkdir config; cat > config/cluster.json" < $(dirname $0)/cluster.json |
| 15 | docker exec -it onos-$i bin/onos-user-key sdn $SSH_KEY >/dev/null 2>&1 |
| 16 | docker exec -it onos-$i bin/onos-user-password onos rocks >/dev/null 2>&1 |
| 17 | done |
| 18 | |
| 19 | function waitForStart { |
| 20 | sleep 5 |
| 21 | for i in {1..3}; do |
| 22 | echo "Waiting for onos-$i startup..." |
| 23 | ip=$(docker container inspect onos-$i | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 24 | for t in {1..30}; do |
| 25 | curl --fail -sS http://$ip:8181/onos/v1/cluster --user onos:rocks 1>/dev/null 2>&1 && break; |
| 26 | sleep 1; |
| 27 | done |
| 28 | onos $ip summary >/dev/null 2>&1 |
| 29 | done |
| 30 | } |
| 31 | |
| 32 | OC1=$(docker container inspect onos-1 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 33 | OC2=$(docker container inspect onos-2 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 34 | OC3=$(docker container inspect onos-3 | grep \"IPAddress | cut -d: -f2 | sort -u | tr -d '", ') |
| 35 | ONOS_INSTANCES="$OC1 $OC2 $OC3" |
| 36 | |
| 37 | waitForStart |
| 38 | |
| 39 | echo "Activating OpenFlow and ProxyARP applications..." |
| 40 | onos $OC1 app activate openflow proxyarp |
| 41 | onos $OC1 |
| 42 | |