-
Notifications
You must be signed in to change notification settings - Fork 2
/
my_app_connectAll.py
42 lines (37 loc) · 1.21 KB
/
my_app_connectAll.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
33
34
35
36
37
38
39
40
41
42
################################
# @author: Qianru Zhou
# @email: [email protected]
# All rights reserved
#################################
from my_api_sparql import query_string_for_hosts, run_query
from my_api_switch_ovs import SwitchAPI as API
import eventlet
def connect_all(*switches):
length = len(switches)
print 'length ' + str(length)
pool = eventlet.GreenPool()
for s in switches:
api = API(s)
queryStr = query_string_for_hosts(s)
q = run_query(queryStr)
q1 = q
#print q.bindings
action_type = 'output'
for count in range(length):
port = 'port' + str(count+1)
mac = 'macAddr' + str(count+1)
for row in q.bindings:
# e.g., from query result 's1-eth3' get '3'
inPort = str(row[str(port)])
inPort = inPort[inPort.index('eth')+3:len(inPort)]
print 'inPort ' + inPort
for row1 in q1.bindings:
if row[port] != row1[port]:
outPort = str(row1[port])
outPort = outPort[outPort.index('eth')+3:len(outPort)]
print 'outPort ' + outPort
print 'mac '+ mac
macAddr = str(row1[mac])
#api.add_flow(in_port=inPort, actions=('output:'+outPort))
pool.spawn(api.add_flow, in_port=inPort, dl_dst=macAddr, actions=('output:'+outPort))
pool.waitall()