Masayoshi Kobayashi | 2da09f5 | 2013-03-26 23:27:22 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | controller=`hostname` |
| 3 | switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'` |
| 4 | |
| 5 | function host2ip (){ |
| 6 | ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'` |
| 7 | echo $ip |
| 8 | } |
| 9 | |
| 10 | url="" |
| 11 | for c in $controller; do |
| 12 | url="$url tcp:`host2ip $c`:6633" |
| 13 | done |
| 14 | |
| 15 | for s in $switches; do |
| 16 | dpid=`sudo ovs-ofctl show $s |grep dpid | awk '{split($4,x,":"); print x[2]}'` |
| 17 | if [ "x$dpid" == "x$1" ]; then |
| 18 | if [ x$2 == "xup" ]; then |
| 19 | sudo ovs-vsctl set-controller $s $url |
Masayoshi Kobayashi | 1dd8de4 | 2013-03-26 23:59:33 +0000 | [diff] [blame] | 20 | echo "$s up" |
Masayoshi Kobayashi | 2da09f5 | 2013-03-26 23:27:22 +0000 | [diff] [blame] | 21 | elif [ x$2 == "xdown" ]; then |
| 22 | sudo ovs-vsctl set-controller $s |
Masayoshi Kobayashi | 1dd8de4 | 2013-03-26 23:59:33 +0000 | [diff] [blame] | 23 | echo "$s down" |
Masayoshi Kobayashi | 2da09f5 | 2013-03-26 23:27:22 +0000 | [diff] [blame] | 24 | else |
Masayoshi Kobayashi | 1dd8de4 | 2013-03-26 23:59:33 +0000 | [diff] [blame] | 25 | echo -n "$s controller: " |
Masayoshi Kobayashi | 2da09f5 | 2013-03-26 23:27:22 +0000 | [diff] [blame] | 26 | sudo ovs-vsctl get-controller $s |
| 27 | fi |
| 28 | fi |
| 29 | done |