blob: cdfdf24a4f6c67236605655e0156a96b13471856 [file] [log] [blame]
Ubuntu82b8a832013-02-06 22:00:11 +00001#! /usr/bin/env python
2import pprint
3import os
4import sys
5import subprocess
6import json
7import argparse
8import io
9import time
10
11from flask import Flask, json, Response, render_template, make_response, request
12
13## Global Var ##
Ubuntuf6ce96c2013-02-07 01:45:07 +000014RestIP="localhost"
Ubuntu82b8a832013-02-06 22:00:11 +000015RestPort=8080
16#DBName="onos-network-map"
Masayoshi Kobayashi13e2ebe2013-03-26 18:38:41 +000017#controllers=["onosgui1", "onosgui2", "onosgui3", "onosgui4"]
18controllers=["onosgui1", "onosgui2", "onosgui3", "onosgui4", "onosgui5", "onosgui6", "onosgui7", "onosgui8"]
Ubuntu82b8a832013-02-06 22:00:11 +000019
20DEBUG=1
21pp = pprint.PrettyPrinter(indent=4)
22
23app = Flask(__name__)
24
25## Worker Functions ##
26def log_error(txt):
27 print '%s' % (txt)
28
29def debug(txt):
30 if DEBUG:
31 print '%s' % (txt)
32
33## Rest APIs ##
34### File Fetch ###
35@app.route('/ui/img/<filename>', methods=['GET'])
36@app.route('/img/<filename>', methods=['GET'])
37@app.route('/css/<filename>', methods=['GET'])
38@app.route('/js/models/<filename>', methods=['GET'])
39@app.route('/js/views/<filename>', methods=['GET'])
40@app.route('/js/<filename>', methods=['GET'])
41@app.route('/lib/<filename>', methods=['GET'])
42@app.route('/', methods=['GET'])
43@app.route('/<filename>', methods=['GET'])
44@app.route('/tpl/<filename>', methods=['GET'])
Masayoshi Kobayashi13e2ebe2013-03-26 18:38:41 +000045@app.route('/ons-demo/<filename>', methods=['GET'])
46@app.route('/ons-demo/js/<filename>', methods=['GET'])
47@app.route('/ons-demo/css/<filename>', methods=['GET'])
48@app.route('/ons-demo/assets/<filename>', methods=['GET'])
49@app.route('/ons-demo/data/<filename>', methods=['GET'])
Ubuntu82b8a832013-02-06 22:00:11 +000050def return_file(filename="index.html"):
51 if request.path == "/":
52 fullpath = "./index.html"
53 else:
54 fullpath = str(request.path)[1:]
55
56 response = make_response(open(fullpath).read())
57 suffix = fullpath.split(".")[-1]
58
59 if suffix == "html" or suffix == "htm":
60 response.headers["Content-type"] = "text/html"
61 elif suffix == "js":
62 response.headers["Content-type"] = "application/javascript"
63 elif suffix == "css":
64 response.headers["Content-type"] = "text/css"
65 elif suffix == "png":
66 response.headers["Content-type"] = "image/png"
67
68 return response
69
Masayoshi Kobayashi13e2ebe2013-03-26 18:38:41 +000070## PROXY API (allows development where the webui is served from someplace other than the controller)##
71ONOS_GUI3_HOST="http://gui3.onlab.us:8080"
72ONOS_LOCAL_HOST="http://localhost:8080" ;# for Amazon EC2
73
74@app.route("/wm/core/topology/switches/all/json")
75def switches():
76 if request.args.get('proxy') == None:
77 host = ONOS_LOCAL_HOST
78 else:
79 host = ONOS_GUI3_HOST
80
81 try:
82 command = "curl -s %s/wm/core/topology/switches/all/json" % (host)
83 print command
84 result = os.popen(command).read()
85 except:
86 print "REST IF has issue"
87 exit
88
89 resp = Response(result, status=200, mimetype='application/json')
90 return resp
91
92@app.route("/wm/core/topology/links/json")
93def links():
94 if request.args.get('proxy') == None:
95 host = ONOS_LOCAL_HOST
96 else:
97 host = ONOS_GUI3_HOST
98
99 try:
100 command = "curl -s %s/wm/core/topology/links/json" % (host)
101 print command
102 result = os.popen(command).read()
103 except:
104 print "REST IF has issue"
105 exit
106
107 resp = Response(result, status=200, mimetype='application/json')
108 return resp
109
110@app.route("/wm/flow/getall/json")
111def flows():
112 if request.args.get('proxy') == None:
113 host = ONOS_LOCAL_HOST
114 else:
115 host = ONOS_GUI3_HOST
116
117 try:
118 command = "curl -s %s/wm/flow/getall/json" % (host)
119 print command
120 result = os.popen(command).read()
121 except:
122 print "REST IF has issue"
123 exit
124
125 resp = Response(result, status=200, mimetype='application/json')
126 return resp
127
128@app.route("/wm/registry/controllers/json")
129def registry_controllers():
130 if request.args.get('proxy') == None:
131 host = ONOS_LOCAL_HOST
132 else:
133 host = ONOS_GUI3_HOST
134
135 try:
136 command = "curl -s %s/wm/registry/controllers/json" % (host)
137 print command
138 result = os.popen(command).read()
139 except:
140 print "REST IF has issue"
141 exit
142
143 resp = Response(result, status=200, mimetype='application/json')
144 return resp
145
146@app.route("/wm/registry/switches/json")
147def registry_switches():
148 if request.args.get('proxy') == None:
149 host = ONOS_LOCAL_HOST
150 else:
151 host = ONOS_GUI3_HOST
152
153 try:
154 command = "curl -s %s/wm/registry/switches/json" % (host)
155 print command
156 result = os.popen(command).read()
157 except:
158 print "REST IF has issue"
159 exit
160
161 resp = Response(result, status=200, mimetype='application/json')
162 return resp
163
Ubuntu82b8a832013-02-06 22:00:11 +0000164
165def node_id(switch_array, dpid):
166 id = -1
167 for i, val in enumerate(switch_array):
168 if val['name'] == dpid:
169 id = i
170 break
171
172 return id
173
Masayoshi Kobayashi13e2ebe2013-03-26 18:38:41 +0000174## API for ON.Lab local GUI ##
Masayoshi Kobayashif63ef2f2013-02-20 21:47:21 +0000175@app.route('/topology', methods=['GET'])
Ubuntu82b8a832013-02-06 22:00:11 +0000176def topology_for_gui():
177 try:
178 command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort)
179 result = os.popen(command).read()
180 parsedResult = json.loads(result)
181 except:
182 log_error("REST IF has issue: %s" % command)
183 log_error("%s" % result)
184 sys.exit(0)
185
186 topo = {}
187 switches = []
188 links = []
Ubuntu37ebda62013-03-01 00:35:31 +0000189 devices = []
Ubuntu82b8a832013-02-06 22:00:11 +0000190
191 for v in parsedResult:
192 if v.has_key('dpid'):
193# if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes
194 dpid = str(v['dpid'])
195 state = str(v['state'])
196 sw = {}
197 sw['name']=dpid
Ubuntu5b2b24a2013-02-27 09:51:13 +0000198 sw['group']= -1
Ubuntu37ebda62013-03-01 00:35:31 +0000199
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000200 if state == "INACTIVE":
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000201 sw['group']=0
Ubuntu82b8a832013-02-06 22:00:11 +0000202 switches.append(sw)
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000203
Ubuntu37ebda62013-03-01 00:35:31 +0000204## Comment in if we need devies
205# sw_index = len(switches) - 1
206# for p in v['ports']:
207# for d in p['devices']:
208# device = {}
209# device['attached_switch']=dpid
210# device['name']=d['mac']
211# if d['state'] == "ACTIVE":
212# device['group']=1000
213# else:
214# device['group']=1001
215#
216# switches.append(device)
217# device_index = len (switches) -1
218# link = {}
219# link['source'] = device_index
220# link['target'] = sw_index
221# link['type'] = -1
222# links.append(link)
223# link = {}
224# link['source'] = sw_index
225# link['target'] = device_index
226# link['type'] = -1
227# links.append(link)
228
Ubuntu5b2b24a2013-02-27 09:51:13 +0000229# try:
230# command = "curl -s \'http://%s:%s/wm/registry/controllers/json\'" % (RestIP, RestPort)
231# result = os.popen(command).read()
232# controllers = json.loads(result)
233# except:
234# log_error("xx REST IF has issue: %s" % command)
235# log_error("%s" % result)
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000236
237 try:
238 command = "curl -s \'http://%s:%s/wm/registry/switches/json\'" % (RestIP, RestPort)
239 result = os.popen(command).read()
240 parsedResult = json.loads(result)
241 except:
242 log_error("REST IF has issue: %s" % command)
243 log_error("%s" % result)
244
245 for key in parsedResult:
246 dpid = key
247 ctrl = parsedResult[dpid][0]['controllerId']
248 sw_id = node_id(switches, dpid)
249 if sw_id != -1:
250 if switches[sw_id]['group'] != 0:
251 switches[sw_id]['group'] = controllers.index(ctrl) + 1
252
Masayoshi Kobayashi3bc5fde2013-02-28 01:02:54 +0000253 try:
254 v1 = "00:00:00:00:00:0a:0d:00"
Ubuntu765deff2013-02-28 18:39:13 +0000255# v1 = "00:00:00:00:00:0d:00:d1"
Masayoshi Kobayashi3bc5fde2013-02-28 01:02:54 +0000256 p1=1
257 v2 = "00:00:00:00:00:0b:0d:03"
Ubuntu765deff2013-02-28 18:39:13 +0000258# v2 = "00:00:00:00:00:0d:00:d3"
259 p2=1
Masayoshi Kobayashi3bc5fde2013-02-28 01:02:54 +0000260 command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
261 result = os.popen(command).read()
262 parsedResult = json.loads(result)
263 except:
264 log_error("No route")
Ubuntu765deff2013-02-28 18:39:13 +0000265 parsedResult = {}
Ubuntu5b2b24a2013-02-27 09:51:13 +0000266
Ubuntu765deff2013-02-28 18:39:13 +0000267 path = []
268 if parsedResult.has_key('flowEntries'):
269 flowEntries= parsedResult['flowEntries']
270 for i, v in enumerate(flowEntries):
271 if i < len(flowEntries) - 1:
272 sdpid= flowEntries[i]['dpid']['value']
273 ddpid = flowEntries[i+1]['dpid']['value']
274 path.append( (sdpid, ddpid))
Ubuntu5b2b24a2013-02-27 09:51:13 +0000275
Ubuntu82b8a832013-02-06 22:00:11 +0000276 try:
277 command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort)
278 result = os.popen(command).read()
279 parsedResult = json.loads(result)
280 except:
281 log_error("REST IF has issue: %s" % command)
282 log_error("%s" % result)
283 sys.exit(0)
284
285 for v in parsedResult:
286 link = {}
287 if v.has_key('dst-switch'):
288 dst_dpid = str(v['dst-switch'])
289 dst_id = node_id(switches, dst_dpid)
290 if v.has_key('src-switch'):
291 src_dpid = str(v['src-switch'])
292 src_id = node_id(switches, src_dpid)
293 link['source'] = src_id
294 link['target'] = dst_id
Masayoshi Kobayashi3bc5fde2013-02-28 01:02:54 +0000295
296 onpath = 0
297 for (s,d) in path:
298 if s == v['src-switch'] and d == v['dst-switch']:
299 onpath = 1
300 break
301 link['type'] = onpath
302
Ubuntu82b8a832013-02-06 22:00:11 +0000303 links.append(link)
304
305 topo['nodes'] = switches
306 topo['links'] = links
307
Ubuntu37ebda62013-03-01 00:35:31 +0000308 pp.pprint(topo)
Ubuntu82b8a832013-02-06 22:00:11 +0000309 js = json.dumps(topo)
310 resp = Response(js, status=200, mimetype='application/json')
311 return resp
312
Ubuntuaea2a682013-02-08 08:30:10 +0000313#@app.route("/wm/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json")
314#@app.route("/wm/topology/toporoute/<srcdpid>/<srcport>/<destdpid>/<destport>/json")
315@app.route("/wm/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json")
316def shortest_path(v1, p1, v2, p2):
317 try:
318 command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort)
319 result = os.popen(command).read()
320 parsedResult = json.loads(result)
321 except:
322 log_error("REST IF has issue: %s" % command)
323 log_error("%s" % result)
324 sys.exit(0)
325
326 topo = {}
327 switches = []
328 links = []
329
330 for v in parsedResult:
331 if v.has_key('dpid'):
332 dpid = str(v['dpid'])
333 state = str(v['state'])
334 sw = {}
335 sw['name']=dpid
336 if str(v['state']) == "ACTIVE":
337 if dpid[-2:-1] == "a":
338 sw['group']=1
339 if dpid[-2:-1] == "b":
340 sw['group']=2
341 if dpid[-2:-1] == "c":
342 sw['group']=3
343 if str(v['state']) == "INACTIVE":
344 sw['group']=0
345
346 switches.append(sw)
347
348 try:
349 command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
350 result = os.popen(command).read()
351 parsedResult = json.loads(result)
352 except:
353 log_error("No route")
354 parsedResult = []
355# exit(1)
356
357 path = [];
358 for i, v in enumerate(parsedResult):
359 if i < len(parsedResult) - 1:
360 sdpid= parsedResult[i]['switch']
361 ddpid = parsedResult[i+1]['switch']
362 path.append( (sdpid, ddpid))
363
364 try:
365 command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort)
366 result = os.popen(command).read()
367 parsedResult = json.loads(result)
368 except:
369 log_error("REST IF has issue: %s" % command)
370 log_error("%s" % result)
371 sys.exit(0)
372
373 for v in parsedResult:
374 link = {}
375 if v.has_key('dst-switch'):
376 dst_dpid = str(v['dst-switch'])
377 dst_id = node_id(switches, dst_dpid)
378 if v.has_key('src-switch'):
379 src_dpid = str(v['src-switch'])
380 src_id = node_id(switches, src_dpid)
381 link['source'] = src_id
382 link['target'] = dst_id
383 onpath = 0
384 for (s,d) in path:
385 if s == v['src-switch'] and d == v['dst-switch']:
386 onpath = 1
387 break
388
389 link['type'] = onpath
390 links.append(link)
391
392 topo['nodes'] = switches
393 topo['links'] = links
394
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000395# pp.pprint(topo)
Ubuntuaea2a682013-02-08 08:30:10 +0000396 js = json.dumps(topo)
397 resp = Response(js, status=200, mimetype='application/json')
398 return resp
399
Ubuntu82b8a832013-02-06 22:00:11 +0000400@app.route("/wm/core/controller/switches/json")
401def query_switch():
402 try:
403 command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort)
404# http://localhost:8080/wm/core/topology/switches/active/json
Masayoshi Kobayashif63ef2f2013-02-20 21:47:21 +0000405 print command
Ubuntu82b8a832013-02-06 22:00:11 +0000406 result = os.popen(command).read()
407 parsedResult = json.loads(result)
408 except:
409 log_error("REST IF has issue: %s" % command)
410 log_error("%s" % result)
411 sys.exit(0)
412
413# print command
414# print result
415 switches_ = []
416 for v in parsedResult:
417 if v.has_key('dpid'):
418 if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes
419 dpid = str(v['dpid'])
420 state = str(v['state'])
421 sw = {}
422 sw['dpid']=dpid
423 sw['active']=state
424 switches_.append(sw)
425
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000426# pp.pprint(switches_)
Ubuntu82b8a832013-02-06 22:00:11 +0000427 js = json.dumps(switches_)
428 resp = Response(js, status=200, mimetype='application/json')
429 return resp
430
431@app.route("/wm/device/")
432def devices():
433 try:
434 command = "curl -s http://%s:%s/graphs/%s/vertices\?key=type\&value=device" % (RestIP, RestPort, DBName)
435 result = os.popen(command).read()
436 parsedResult = json.loads(result)['results']
437 except:
438 log_error("REST IF has issue: %s" % command)
439 log_error("%s" % result)
440 sys.exit(0)
441
442 devices = []
443 for v in parsedResult:
444 dl_addr = v['dl_addr']
445 nw_addr = v['nw_addr']
446 vertex = v['_id']
447 mac = []
448 mac.append(dl_addr)
449 ip = []
450 ip.append(nw_addr)
451 device = {}
452 device['entryClass']="DefaultEntryClass"
453 device['mac']=mac
454 device['ipv4']=ip
455 device['vlan']=[]
456 device['lastSeen']=0
457 attachpoints =[]
458
459 port, dpid = deviceV_to_attachpoint(vertex)
460 attachpoint = {}
461 attachpoint['port']=port
462 attachpoint['switchDPID']=dpid
463 attachpoints.append(attachpoint)
464 device['attachmentPoint']=attachpoints
465 devices.append(device)
466
467 print devices
468 js = json.dumps(devices)
469 resp = Response(js, status=200, mimetype='application/json')
470 return resp
471
472#{"entityClass":"DefaultEntityClass","mac":["7c:d1:c3:e0:8c:a3"],"ipv4":["192.168.2.102","10.1.10.35"],"vlan":[],"attachmentPoint":[{"port":13,"switchDPID":"00:01:00:12:e2:78:32:44","errorStatus":null}],"lastSeen":1357333593496}
473
Ubuntu82b8a832013-02-06 22:00:11 +0000474## return fake stat for now
475@app.route("/wm/core/switch/<switchId>/<statType>/json")
476def switch_stat(switchId, statType):
477 if statType == "desc":
478 desc=[{"length":1056,"serialNumber":"None","manufacturerDescription":"Nicira Networks, Inc.","hardwareDescription":"Open vSwitch","softwareDescription":"1.4.0+build0","datapathDescription":"None"}]
479 ret = {}
480 ret[switchId]=desc
481 elif statType == "aggregate":
482 aggr = {"packetCount":0,"byteCount":0,"flowCount":0}
483 ret = {}
484 ret[switchId]=aggr
485 else:
486 ret = {}
487
488 js = json.dumps(ret)
489 resp = Response(js, status=200, mimetype='application/json')
490 return resp
491
492
493@app.route("/wm/topology/links/json")
494def query_links():
495 try:
496 command = 'curl -s http://%s:%s/graphs/%s/vertices?key=type\&value=port' % (RestIP, RestPort, DBName)
Masayoshi Kobayashif63ef2f2013-02-20 21:47:21 +0000497 print command
Ubuntu82b8a832013-02-06 22:00:11 +0000498 result = os.popen(command).read()
499 parsedResult = json.loads(result)['results']
500 except:
501 log_error("REST IF has issue: %s" % command)
502 log_error("%s" % result)
503 sys.exit(0)
504
505 debug("query_links %s" % command)
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000506# pp.pprint(parsedResult)
Ubuntu82b8a832013-02-06 22:00:11 +0000507 sport = []
508 links = []
509 for v in parsedResult:
510 srcport = v['_id']
511 try:
512 command = "curl -s http://%s:%s/graphs/%s/vertices/%d/out?_label=link" % (RestIP, RestPort, DBName, srcport)
513 print command
514 result = os.popen(command).read()
515 linkResults = json.loads(result)['results']
516 except:
517 log_error("REST IF has issue: %s" % command)
518 log_error("%s" % result)
519 sys.exit(0)
520
521 for p in linkResults:
522 if p.has_key('type') and p['type'] == "port":
523 dstport = p['_id']
524 (sport, sdpid) = portV_to_port_dpid(srcport)
525 (dport, ddpid) = portV_to_port_dpid(dstport)
526 link = {}
527 link["src-switch"]=sdpid
528 link["src-port"]=sport
529 link["src-port-state"]=0
530 link["dst-switch"]=ddpid
531 link["dst-port"]=dport
532 link["dst-port-state"]=0
533 link["type"]="internal"
534 links.append(link)
535
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000536# pp.pprint(links)
Ubuntu82b8a832013-02-06 22:00:11 +0000537 js = json.dumps(links)
538 resp = Response(js, status=200, mimetype='application/json')
539 return resp
540
Masayoshi Kobayashi1407a502013-02-27 06:23:08 +0000541topo_less = {
542 "nodes" : [
543 {"name" : "00:a0", "group" : 1},
544 {"name" : "00:a1", "group" : 1},
545 {"name" : "00:a2", "group" : 1},
546 ],
547 "links" : [
548 {"source" :0, "target": 1},
549 {"source" :1, "target": 0},
550 {"source" :0, "target": 2},
551 {"source" :2, "target": 0},
552 {"source" :1, "target": 2},
553 {"source" :2, "target": 1},
554 ]
555}
556
557topo_more = {
558 "nodes" : [
559 {"name" : "00:a3", "group" : 2},
560 {"name" : "00:a0", "group" : 1},
561 {"name" : "00:a1", "group" : 1},
562 {"name" : "00:a2", "group" : 1},
563 ],
564 "links" : [
565 {"source" :1, "target": 2},
566 {"source" :2, "target": 1},
567 {"source" :1, "target": 3},
568 {"source" :3, "target": 1},
569 {"source" :2, "target": 3},
570 {"source" :3, "target": 2},
571 {"source" :0, "target": 2},
572 ]
573}
574
575@app.route("/topology_more")
576def topology_more():
577 topo = topo_more
578 js = json.dumps(topo)
579 resp = Response(js, status=200, mimetype='application/json')
580 return resp
581
582@app.route("/topology_less")
583def topology_less():
584 topo = topo_less
585 js = json.dumps(topo)
586 resp = Response(js, status=200, mimetype='application/json')
587 return resp
588
589cont_status1 = [
590 {"name":"onos9vpc", "onos": 1, "cassandra": 1},
591 {"name":"onos10vpc", "onos": 0, "cassandra": 1},
592 {"name":"onos11vpc", "onos": 1, "cassandra": 0},
593 {"name":"onos12vpc", "onos": 1, "cassandra": 0}]
594
595cont_status2 = [
596 {"name":"onos9vpc", "onos": 0, "cassandra": 1},
597 {"name":"onos10vpc", "onos": 0, "cassandra": 1},
598 {"name":"onos11vpc", "onos": 0, "cassandra": 1},
599 {"name":"onos12vpc", "onos": 0, "cassandra": 1}]
600
601@app.route("/controller_status1")
602def controller_status1():
603 status = cont_status1
604 js = json.dumps(status)
605 resp = Response(js, status=200, mimetype='application/json')
606 pp.pprint(resp)
607 return resp
608
609@app.route("/controller_status2")
610def controller_status2():
611 status = cont_status2
612 js = json.dumps(status)
613 resp = Response(js, status=200, mimetype='application/json')
614 pp.pprint(resp)
615 return resp
616
Ubuntuc016ba12013-02-27 21:53:41 +0000617@app.route("/controller_status")
618def controller_status():
619 onos_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh status | awk '{print $1}'"
620 #cassandra_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-cassandra.sh status"
621
622 cont_status=[]
623 for i in controllers:
624 status={}
625 onos=os.popen(onos_check % i).read()[:-1]
626 status["name"]=i
627 status["onos"]=onos
Masayoshi Kobayashi5e91bdf2013-03-15 01:22:51 +0000628 status["cassandra"]=0
Ubuntuc016ba12013-02-27 21:53:41 +0000629 cont_status.append(status)
630
631 js = json.dumps(cont_status)
632 resp = Response(js, status=200, mimetype='application/json')
633 pp.pprint(js)
634 return resp
635
Ubuntu82b8a832013-02-06 22:00:11 +0000636if __name__ == "__main__":
637 if len(sys.argv) > 1 and sys.argv[1] == "-d":
638 print "-- query all switches --"
639 query_switch()
640 print "-- query topo --"
641 topology_for_gui()
642# print "-- query all links --"
643# query_links()
644# print "-- query all devices --"
645# devices()
646 else:
647 app.debug = True
Masayoshi Kobayashif63ef2f2013-02-20 21:47:21 +0000648 app.run(threaded=True, host="0.0.0.0", port=9000)