-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson_http_handler.py
More file actions
97 lines (77 loc) · 2.54 KB
/
Copy pathjson_http_handler.py
File metadata and controls
97 lines (77 loc) · 2.54 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
__author__ = 'venkat'
import httplib2
import json
from rest_url_database import *
class HttpJsonHandler:
def __init__(self):
print("Inside Class - HttpJsonHandler Constructor")
self.resp = None
self.nodes = None
self.flows = None
self.ports = None
self.hosts = None
self.links = None
self.content = None
return
def getnodeinfo(self):
global h
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
'''
Get the List of nodes available in the network
'''
print(REST_URL_FOR_NODE)
self.resp, self.content = h.request(REST_URL_FOR_NODE, 'GET')
nodes = json.loads(self.content.decode())
return nodes
def getflowinfo (self, switchid):
global h
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
'''
Get the List of flows available in the network
'''
flow_rest_url = REST_URL_FOR_FLOW + switchid
print(flow_rest_url)
self.resp, self.content = h.request(flow_rest_url, 'GET')
self.flows = json.loads(self.content.decode())
return self.flows
def getportinfo(self, switchid):
global h
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
'''
Get the List of ports available in the switch
'''
port_rest_url = REST_URL_FOR_PORT + switchid
print(port_rest_url)
self.resp, self.content = h.request(port_rest_url, 'GET')
self.ports = json.loads(self.content.decode())
return self.ports
def gethostinfo(self):
global h
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
'''
Get the List of hosts connected to the switch
'''
print(REST_URL_FOR_HOST)
self.resp, self.content = h.request(REST_URL_FOR_HOST, 'GET')
self.hosts = json.loads(self.content.decode())
return self.hosts
def getlinkinfo(self, switchid):
global h
h = httplib2.Http(".cache")
h.add_credentials('admin', 'admin')
'''
Get the List of links connected to the switch
'''
link_rest_url = REST_URL_FOR_LINK + switchid
print(link_rest_url)
self.resp, self.content = h.request(link_rest_url, 'GET')
self.links = json.loads(self.content.decode())
return self.links
switchid = "00:00:00:00:00:00:00:01"
flow = HttpJsonHandler()
flow.getnodeinfo()
flow.getlinkinfo(switchid)