-
Notifications
You must be signed in to change notification settings - Fork 0
/
manualController.py
32 lines (28 loc) · 1.11 KB
/
manualController.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
import time
from threading import Thread
import os
import commands
import time
bridge_list = ['s1','s2','s3','s4','s5','s6','s7','s8','s9','s10']
while True:
time.sleep(3)
reponse = ""
for i in range(0,10):
getcontr = commands.getstatusoutput("sudo ovs-vsctl get-controller "+ bridge_list[i])
if(getcontr[1] == "tcp:127.0.0.1:6633"):
response = commands.getstatusoutput("sudo ovs-vsctl get controller "+ bridge_list[i] + " is_connected")
if response[1] == "false":
start = time.time()
os.system("sudo ovs-vsctl set-controller " +bridge_list[i]+ " tcp:127.0.0.1:6639")
print("switch :: "+bridge_list[i]+" is connected to controller:c2")
end = time.time()
print(end - start)
elif(getcontr[1] == "tcp:127.0.0.1:6639"):
response = commands.getstatusoutput("sudo ovs-vsctl get controller "+ bridge_list[i] + " is_connected")
if response[1] == "false":
start = time.time()
os.system("sudo ovs-vsctl set-controller " +bridge_list[i]+ " tcp:127.0.0.1:6633")
print("switch :: "+bridge_list[i]+" is connected to controller:c1")
end = time.time()
print(end - start)