-
Notifications
You must be signed in to change notification settings - Fork 1
/
onos_flow.py
65 lines (48 loc) · 1.44 KB
/
onos_flow.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
import requests
import json
import argparse
from requests.auth import HTTPBasicAuth
import flowtable
def ACL(IP,ID):
reqURL = "http://"+IP+":8181/onos/v1/flows"
reqURL_dev = reqURL+ID
print(reqURL)
print(reqURL_dev)
fid, flow, rcode = GET(reqURL)
print(fid)
print(rcode)
print(flows)
"""flowid = 18577352444689406
rcode = DEL(reqURL_dev,flowid)
"""
mac =
def GET(URL):
response = requests.get(URL, auth=('onos', 'rocks'))
print response.status_code
flow_resp = response.json()
flow_ids = []
for flow in flow_resp['flows']:
#print('hello')
flow_ids.append(flow['id'])
return flow_ids, flow_resp, response.status_code
def POST(URL, flow_json):
json_rule = flow_json
headers = {'Content-Type':'application/json' , 'Accept':'application/json'}
response = requests.post(URL, data=json_rule, auth=('onos', 'rocks'), headers=headers)
print response.status_code
return response.status_code
def DEL(URL, flowid):
url_del = URL+"/"+str(flowid)
print(url_del)
#headers = {'Content-Type':'application/json' ,'Accept: application/json'}
response = requests.delete(url_del, auth=('onos', 'rocks'))
#print response.status_code
return response.status_code
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("ControllerIP",help="Specify Controller IP")
args = parser.parse_args()
#devID = "/of%3A0000687f7429badf"
devID = "/of%3A0000000000000001"
ACL(args.ControllerIP,devID)