blob: eba0f34b53802cf879b782ef3f5f6ec15bfa22fc [file] [log] [blame]
Masayoshi Kobayashi2da09f52013-03-26 23:27:22 +00001#! /bin/bash
2controller=`hostname`
3switches=`ifconfig -a | grep sw |grep -v eth | awk '{print $1}'`
4
5function host2ip (){
6 ip=`grep $1 /etc/hosts |grep -v "ip6"| awk '{print $1}'`
7 echo $ip
8}
9
10url=""
11for c in $controller; do
12 url="$url tcp:`host2ip $c`:6633"
13done
14
15for 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 Kobayashi1dd8de42013-03-26 23:59:33 +000020 echo "$s up"
Masayoshi Kobayashi2da09f52013-03-26 23:27:22 +000021 elif [ x$2 == "xdown" ]; then
22 sudo ovs-vsctl set-controller $s
Masayoshi Kobayashi1dd8de42013-03-26 23:59:33 +000023 echo "$s down"
Masayoshi Kobayashi2da09f52013-03-26 23:27:22 +000024 else
Masayoshi Kobayashi1dd8de42013-03-26 23:59:33 +000025 echo -n "$s controller: "
Masayoshi Kobayashi2da09f52013-03-26 23:27:22 +000026 sudo ovs-vsctl get-controller $s
27 fi
28 fi
29done