Cleaned up the simple GUI scripts.
* Removed unused functions/code from topology_rest.py
* Removed checking of Cassandra process status
* Removed the topology_rest_napi.py script which was a clone of topology_rest.py
Change-Id: I7039fd59ae1324564e0a87c3788fd3c59dab1cb4
diff --git a/web/topology_rest.py b/web/topology_rest.py
index 64f6275..703fddb 100755
--- a/web/topology_rest.py
+++ b/web/topology_rest.py
@@ -1,34 +1,23 @@
#! /usr/bin/env python
-import pprint
import os
-import sys
-import subprocess
import json
-import argparse
-import io
-import time
-import random
-import re
from urllib2 import Request, urlopen, URLError, HTTPError
-
from flask import Flask, json, Response, render_template, make_response, request
-CONFIG_FILE=os.getenv("HOME") + "/ONOS/web/config.json"
-LINK_FILE=os.getenv("HOME") + "/ONOS/web/link.json"
-ONOSDIR=os.getenv("HOME") + "/ONOS"
+CONFIG_FILE="config.json"
## Global Var for this proxy script setting.
# "0.0.0.0" means any interface
-ProxyIP="0.0.0.0"
-ProxyPort=9000
+GuiIp="0.0.0.0"
+GuiPort=9000
## Global Var for ON.Lab local REST ##
+# The GUI can be accessed at <this_host>:9000/onos-topology.html
RestIP="localhost"
RestPort=8080
ONOS_DEFAULT_HOST="localhost" ;# Has to set if LB=False
DEBUG=1
-pp = pprint.PrettyPrinter(indent=4)
app = Flask(__name__)
def read_config():
@@ -47,25 +36,15 @@
def log_error(txt):
print '%s' % (txt)
-def debug(txt):
- if DEBUG:
- print '%s' % (txt)
-
### File Fetch ###
@app.route('/ui/img/<filename>', methods=['GET'])
-@app.route('/img/<filename>', methods=['GET'])
-@app.route('/css/<filename>', methods=['GET'])
-@app.route('/js/models/<filename>', methods=['GET'])
-@app.route('/js/views/<filename>', methods=['GET'])
@app.route('/js/<filename>', methods=['GET'])
-@app.route('/lib/<filename>', methods=['GET'])
@app.route('/log/<filename>', methods=['GET'])
@app.route('/', methods=['GET'])
@app.route('/<filename>', methods=['GET'])
-@app.route('/tpl/<filename>', methods=['GET'])
def return_file(filename="index.html"):
if request.path == "/":
- fullpath = "./index.html"
+ fullpath = "./onos-topology.html"
else:
fullpath = str(request.path)[1:]
@@ -99,17 +78,15 @@
try:
response = urlopen(url)
except URLError, e:
- print "get_json: REST IF %s has issue. Reason: %s" % (url, e.reason)
+ log_error("get_json: REST IF %s has issue. Reason: %s" % (url, e.reason))
result = ""
return (500, result)
except HTTPError, e:
- print "get_json: REST IF %s has issue. Code %s" % (url, e.code)
+ log_error("get_json: REST IF %s has issue. Code %s" % (url, e.code))
result = ""
return (e.code, result)
- print response
result = response.read()
-# parsedResult = json.loads(result)
return (code, result)
@@ -176,7 +153,6 @@
log_error("REST IF has issue: %s" % url)
log_error("%s" % result)
return
-# sys.exit(0)
for v in parsedResult:
link = {}
@@ -189,13 +165,6 @@
link['source'] = src_id
link['target'] = dst_id
- #onpath = 0
- #for (s,d) in path:
- # if s == v['src-switch'] and d == v['dst-switch']:
- # onpath = 1
- # break
- #link['type'] = onpath
-
links.append(link)
topo['nodes'] = switches
@@ -205,137 +174,6 @@
resp = Response(js, status=200, mimetype='application/json')
return resp
-@app.route("/wm/floodlight/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json")
-def shortest_path(v1, p1, v2, p2):
- try:
- url = "http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort)
- (code, result) = get_json(url)
- parsedResult = json.loads(result)
- except:
- log_error("REST IF has issue: %s" % command)
- log_error("%s" % result)
- return
-
- topo = {}
- switches = []
- links = []
-
- for v in parsedResult:
- if v.has_key('dpid'):
- dpid = str(v['dpid'])
- state = str(v['state'])
- sw = {}
- sw['name']=dpid
- if str(v['state']) == "ACTIVE":
- if dpid[-2:-1] == "a":
- sw['group']=1
- if dpid[-2:-1] == "b":
- sw['group']=2
- if dpid[-2:-1] == "c":
- sw['group']=3
- if str(v['state']) == "INACTIVE":
- sw['group']=0
-
- switches.append(sw)
-
- try:
- url = "http://%s:%s/wm/onos/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2)
- (code, result) = get_json(url)
- parsedResult = json.loads(result)
- except:
- log_error("No route")
- parsedResult = []
-
- path = [];
- for i, v in enumerate(parsedResult):
- if i < len(parsedResult) - 1:
- sdpid= parsedResult['flowEntries'][i]['dpid']['value']
- ddpid= parsedResult['flowEntries'][i+1]['dpid']['value']
- path.append( (sdpid, ddpid))
-
- try:
- url = "http://%s:%s/wm/onos/topology/links/json" % (RestIP, RestPort)
- (code, result) = get_json(url)
- parsedResult = json.loads(result)
- except:
- log_error("REST IF has issue: %s" % command)
- log_error("%s" % result)
- return
-
- for v in parsedResult:
- link = {}
- if v.has_key('dst-switch'):
- dst_dpid = str(v['dst-switch'])
- dst_id = node_id(switches, dst_dpid)
- if v.has_key('src-switch'):
- src_dpid = str(v['src-switch'])
- src_id = node_id(switches, src_dpid)
- link['source'] = src_id
- link['target'] = dst_id
- onpath = 0
- for (s,d) in path:
- if s == v['src-switch'] and d == v['dst-switch']:
- onpath = 1
- break
-
- link['type'] = onpath
- links.append(link)
-
- topo['nodes'] = switches
- topo['links'] = links
-
- js = json.dumps(topo)
- resp = Response(js, status=200, mimetype='application/json')
- return resp
-
-@app.route("/wm/floodlight/core/controller/switches/json")
-def query_switch():
- try:
- url = "http://%s:%s/wm/onos/topology/switches/json" % (RestIP, RestPort)
- (code, result) = get_json(url)
- parsedResult = json.loads(result)
- except:
- log_error("REST IF has issue: %s" % url)
- log_error("%s" % result)
- return
-# sys.exit(0)
-
-# print command
-# print result
- switches_ = []
- for v in parsedResult:
- if v.has_key('dpid'):
- if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes
- dpid = str(v['dpid'])
- state = str(v['state'])
- sw = {}
- sw['dpid']=dpid
- sw['active']=state
- switches_.append(sw)
-
-# pp.pprint(switches_)
- js = json.dumps(switches_)
- resp = Response(js, status=200, mimetype='application/json')
- return resp
-
-## return fake stat for now
-@app.route("/wm/floodlight/core/switch/<switchId>/<statType>/json")
-def switch_stat(switchId, statType):
- if statType == "desc":
- desc=[{"length":1056,"serialNumber":"None","manufacturerDescription":"Nicira Networks, Inc.","hardwareDescription":"Open vSwitch","softwareDescription":"1.4.0+build0","datapathDescription":"None"}]
- ret = {}
- ret[switchId]=desc
- elif statType == "aggregate":
- aggr = {"packetCount":0,"byteCount":0,"flowCount":0}
- ret = {}
- ret[switchId]=aggr
- else:
- ret = {}
-
- js = json.dumps(ret)
- resp = Response(js, status=200, mimetype='application/json')
- return resp
-
@app.route("/controller_status")
def controller_status():
url= "http://%s:%d/wm/onos/registry/controllers/json" % (RestIP, RestPort)
@@ -351,7 +189,6 @@
onos=0
status["name"]=i
status["onos"]=onos
- status["cassandra"]=0
cont_status.append(status)
js = json.dumps(cont_status)
@@ -359,27 +196,6 @@
return resp
if __name__ == "__main__":
- random.seed()
read_config()
- if len(sys.argv) > 1 and sys.argv[1] == "-d":
- # for debugging
- #add_flow("00:00:00:00:00:00:02:02", 1, "00:00:00:00:00:00:03:02", 1, "00:00:00:00:02:02", "00:00:00:00:03:0c")
- #proxy_link_change("up", "00:00:00:00:ba:5e:ba:11", 1, "00:00:00:00:00:00:00:00", 1)
- #proxy_link_change("down", "00:00:20:4e:7f:51:8a:35", 1, "00:00:00:00:00:00:00:00", 1)
- #proxy_link_change("up", "00:00:00:00:00:00:02:03", 1, "00:00:00:00:00:00:00:00", 1)
- #proxy_link_change("down", "00:00:00:00:00:00:07:12", 1, "00:00:00:00:00:00:00:00", 1)
- #print "-- query all switches --"
- #query_switch()
- #print "-- query topo --"
- #topology_for_gui()
- ##print "-- query all links --"
- ##query_links()
- #print "-- query all devices --"
- #devices()
- #links()
- #switches()
- #reset_demo()
- pass
- else:
- app.debug = True
- app.run(threaded=True, host=ProxyIP, port=ProxyPort)
\ No newline at end of file
+ app.debug = True
+ app.run(threaded=True, host=GuiIp, port=GuiPort)