Commit 884bc060 authored by Tomas Hlavacek's avatar Tomas Hlavacek

Dispaly ranges implemented.

Lot of things has to be reworked in order to introduce range display of
large results (it should have been take into account in the beginning)...
parent cfe4a8d5
......@@ -21,6 +21,7 @@
header = 'Universal looking glass test header'
refresh_interval = 5 # interval of html refresh
usage_limit = 1 # maximum concurrently processed requests
range_step = 100 # number of table lines in the decorated output per page
# Settings defaults
always_start_thread = True # True is highly recommended
......
......@@ -111,6 +111,7 @@
<p>Select router to perform operation on, then select a command to perform and add (optional) argument if needed.</p>
<form action="${getFormURL()}" method="post">
<input type="hidden" name="sessionid" value="$default_sessionid" py:if="defined('default_sessionid') and (default_sessionid)" />
<input type="hidden" name="resrange" value="$resrange" py:if="defined('resrange')" />
<table summary="Form settings">
<tbody>
<tr>
......@@ -157,7 +158,7 @@
</table>
</form>
<div id="result">
<hr py:if="(defined('result') and result) or (defined('refresh') and (refresh>0))"/>
<hr/>
<py:choose>
<py:when test="defined('result') and result">
${result}
......@@ -170,6 +171,31 @@
<em>The page is going to be refreshed in $refresh seconds.</em>
</p>
</div>
<div id="range">
<py:if test="defined('resrangeb') and resrangeb">
<br/>
<p> [
<py:for each="rb in resrangeb[:-1]">
<py:choose>
<py:when test="rb[1]">
<a href="${rb[1]}">${rb[0]}</a> |
</py:when>
<py:otherwise>
${rb[0]} |
</py:otherwise>
</py:choose>
</py:for>
<py:choose>
<py:when test="resrangeb[-1][1]">
<a href="${resrangeb[-1][1]}">${resrangeb[-1][0]}</a> ]
</py:when>
<py:otherwise>
${resrangeb[-1][0]} ]
</py:otherwise>
</py:choose>
</p>
</py:if>
</div>
<div id="footer">
<hr/>
<p class="legales" align="right"><small>(c) 2012 Tomas Hlavacek</small></p>
......
......@@ -41,7 +41,7 @@ import ulgmodel
### CGI output handler
class Session(object):
def __init__(self,sessionid=None,routerid=None,commandid=None,parameters=[],result=None,finished=False,error=None):
def __init__(self,sessionid=None,routerid=None,commandid=None,parameters=[],result=None,finished=False,error=None,resrange=None):
if(sessionid == None):
self.sessionid = self.__genSessionId__()
else:
......@@ -52,6 +52,8 @@ class Session(object):
self.parameters=parameters
self.error=error
self.finished=finished
self.range=resrange
self.resultlen=0
self.save()
......@@ -158,12 +160,15 @@ class Session(object):
except:
return None
def getDecoratedResult(self,decorator_helper):
def getDecoratedResult(self,decorator_helper,resrange=0):
if(self.getError()):
return decorator_helper.pre(self.getResult())
else:
if(self.getResult()):
return self.getCommand().decorateResult(self.getResult(),self.getRouter(),decorator_helper)
result = self.getResult()
if(result):
dr = self.getCommand().decorateResult(result,self.getRouter(),decorator_helper,resrange)
self.resultlines = dr[1]
return dr[0]
else:
return None
......@@ -181,6 +186,8 @@ class Session(object):
if(os.path.isfile(fn)):
f=open(fn,'w')
f.close()
self.resultlines = 0
except:
pass
......@@ -201,6 +208,17 @@ class Session(object):
def setError(self,error=None):
self.error=error
self.save()
def getRange(self):
return self.range
def setRange(self,resrange):
self.range=resrange
self.save()
def getMaxRange(self):
return self.resultlines
class DecoratorHelper:
def __init__(self):
......@@ -221,8 +239,11 @@ class DecoratorHelper:
def getRuncommandURL(self,parameters={}):
return self.getURL('runcommand',parameters)
def getDisplayURL(self,sessionid):
return self.getURL('display',{'sessionid':sessionid})
def getDisplayURL(self,sessionid,resrange=None):
if(resrange):
return self.getURL('display',{'sessionid':sessionid,'resrange':resrange})
else:
return self.getURL('display',{'sessionid':sessionid})
def getDebugURL(self,parameters={}):
return self.getURL('debug',parameters)
......@@ -425,7 +446,37 @@ class ULGCgi:
return self.HTTPRedirect(self.decorator_helper.getDisplayURL(session.getSessionId()))
def renderULGResult(self,sessionid=None):
def renderULGResult(self,sessionid=None,resrange=0):
def getRangeStepURLs(session,decorator_helper):
cur_range = session.getRange()
max_range = session.getMaxRange()
if(max_range < defaults.range_step):
return None
res = []
if((cur_range - defaults.range_step * 100) >= 0):
res.append(('<<',decorator_helper.getDisplayURL(session.getSessionId(),str(cur_range - defaults.range_step * 100))))
if((cur_range - defaults.range_step * 10) >= 0):
res.append(('<',decorator_helper.getDisplayURL(session.getSessionId(),str(cur_range - defaults.range_step * 10))))
boundary_size = 8
leftb = max(0,cur_range - boundary_size*defaults.range_step)
rightb = min(leftb + 2*boundary_size*defaults.range_step,max_range)
for rb in range(leftb,rightb,defaults.range_step):
if(rb != cur_range):
res.append((str(rb),decorator_helper.getDisplayURL(session.getSessionId(),str(rb))))
else:
res.append((str(rb),None))
if((cur_range + defaults.range_step * 10) < max_range):
res.append(('>',decorator_helper.getDisplayURL(session.getSessionId(),str(cur_range + defaults.range_step * 10))))
if((cur_range + defaults.range_step * 100) < max_range):
res.append(('>>',decorator_helper.getDisplayURL(session.getSessionId(),str(cur_range + defaults.range_step * 100))))
return res
if(sessionid==None):
return self.HTTPRedirect(self.decorator_helper.getErrorURL())
......@@ -433,7 +484,9 @@ class ULGCgi:
if(session == None):
return self.HTTPRedirect(self.decorator_helper.getErrorURL())
result_text = session.getDecoratedResult(self.decorator_helper)
session.setRange(int(resrange))
result_text = session.getDecoratedResult(self.decorator_helper,session.getRange())
if(session.isFinished()):
refresh=None
......@@ -452,7 +505,9 @@ class ULGCgi:
default_sessionid=sessionid,
result=Markup(result_text) if(result_text) else None,
refresh=refresh,
getFormURL=self.decorator_helper.getRuncommandURL
getFormURL=self.decorator_helper.getRuncommandURL,
resrange=str(session.getRange()),
resrangeb=getRangeStepURLs(session,self.decorator_helper),
).render('html', doctype='html')
def renderULGError(self,sessionid=None,**params):
......@@ -502,7 +557,7 @@ class ULGCgi:
print self.renderULGAction(routerid,commandid,sessionid,**params)
def display(self,sessionid=None,**params):
print self.renderULGResult(sessionid)
print self.renderULGResult(sessionid,**params)
def error(self,sessionid=None,**params):
print self.renderULGError(sessionid,**params)
......
......@@ -42,7 +42,7 @@ bird_sock_reply_end_regexp = re.compile(BIRD_SOCK_REPLY_END_REGEXP)
bird_rt_line_regexp = re.compile(BIRD_RT_LINE_REGEXP)
def parseBirdShowProtocols(text):
def parseBirdShowProtocols(text,resrange=None):
def parseShowProtocolsLine(line):
sh_proto_line_regexp = re.compile(BIRD_SHOW_PROTO_LINE_REGEXP)
m = sh_proto_line_regexp.match(line)
......@@ -59,6 +59,7 @@ def parseBirdShowProtocols(text):
header = []
table = []
for l in str.splitlines(text):
if(re.match('^\s*$',l)):
continue
......@@ -73,7 +74,10 @@ def parseBirdShowProtocols(text):
else:
ulgmodel.log("ulgbird.parseBirdShowProtocols skipping unparsable line"+l)
return (header,table)
if(resrange):
return (header,table[resrange:resrange+defaults.range_step],len(table))
else:
return (header,table,len(table))
# classes
......@@ -122,21 +126,21 @@ class BirdShowProtocolsCommand(ulgmodel.TextCommand):
return tl
def decorateResult(self,result,router=None,decorator_helper=None):
def decorateResult(self,result,router=None,decorator_helper=None,resrange=0):
if((not router) or (not decorator_helper)):
return "<pre>\n%s\n</pre>" % result
else:
pr = parseBirdShowProtocols(result)
pr = parseBirdShowProtocols(result,resrange)
table_header = pr[0]
table = []
for tl in pr[1]:
for tl in pr[1][resrange:resrange+defaults.range_step]:
# skip when there is a filter and it does not match the protocol type
if(self.fltr) and (not re.match(self.fltr,tl[1])):
continue
table.append(self._decorateTableLine(tl,router,decorator_helper))
return ulgmodel.TableDecorator(table,table_header).decorate()
return (ulgmodel.TableDecorator(table,table_header).decorate(),pr[2])
class BirdBGPPeerSelectCommand(ulgmodel.TextCommand):
......@@ -182,7 +186,7 @@ class BirdShowRouteProtocolCommand(BirdBGPPeerSelectCommand):
return result
def decorateResult(self,result,router=None,decorator_helper=None):
def decorateResult(self,result,router=None,decorator_helper=None,resrange=0):
if((not router) or (not decorator_helper)):
return "<pre>\n%s\n</pre>" % result
......@@ -195,9 +199,12 @@ class BirdShowRouteProtocolCommand(BirdBGPPeerSelectCommand):
'Metric',
'Info',]
table = self._genTable(str.splitlines(result),decorator_helper,router)
lines = str.splitlines(result)
result_len = len(lines)
lines = lines[resrange:resrange+defaults.range_step]
table = self._genTable(lines,decorator_helper,router)
return ulgmodel.TableDecorator(table,table_header).decorate()
return (ulgmodel.TableDecorator(table,table_header).decorate(),result_len)
class BirdShowRouteAllCommand(ulgmodel.TextCommand):
......
......@@ -56,7 +56,6 @@ BGP_YELLOW_STATES = ['Idle (Admin)',]
def matchCiscoBGPLines(header,lines):
# TODO
# Match cisco lines formatted to be aligned to columns. Like:
# Network Next Hop Metric LocPrf Weight Path
# * 79.170.248.0/21 91.210.16.6 300 0 20723 i
......@@ -273,7 +272,7 @@ class CiscoCommandBgpIPv46Sum(ulgmodel.TextCommand):
else:
raise Exception("Can not parse line: "+line)
def decorateResult(self,result,router=None,decorator_helper=None):
def decorateResult(self,result,router=None,decorator_helper=None,resrange=0):
if((not router) or (not decorator_helper)):
return "<pre>\n%s\n</pre>" % result
......@@ -302,7 +301,10 @@ class CiscoCommandBgpIPv46Sum(ulgmodel.TextCommand):
# not yet in the table body, append before-table section
before = before + l + '\n'
return ulgmodel.TableDecorator(table,table_header,before=decorator_helper.pre(before)).decorate()
result_len = len(table)
table = table[resrange:resrange+defaults.range_step]
return (ulgmodel.TableDecorator(table,table_header,before=decorator_helper.pre(before)).decorate(),result_len)
class CiscoCommandBgpIPv4Sum(CiscoCommandBgpIPv46Sum):
......@@ -322,12 +324,12 @@ class CiscoCommandBgpIPv6Sum(CiscoCommandBgpIPv46Sum):
def __init__(self,name=None,peer_address_command=None,peer_received_command=None):
return CiscoCommandBgpIPv46Sum.__init__(self,name,peer_address_command,peer_received_command)
def decorateResult(self,result,router=None,decorator_helper=None):
def decorateResult(self,result,router=None,decorator_helper=None,resrange=0):
res=''
for l in normalizeBGPIPv6SumSplitLines(str.splitlines(result)):
res = res + "\n" + l
return super(CiscoCommandBgpIPv6Sum,self).decorateResult(res,router,decorator_helper)
return super(CiscoCommandBgpIPv6Sum,self).decorateResult(res,router,decorator_helper,resrange)
class CiscoCommandShowBgpIPv4Neigh(ulgmodel.TextCommand):
......@@ -396,7 +398,7 @@ class CiscoCommandShowBgpIPv46Select(ulgmodel.TextCommand):
])
return result
def decorateResult(self,result,router=None,decorator_helper=None):
def decorateResult(self,result,router=None,decorator_helper=None,resrange=0):
if((not router) or (not decorator_helper)):
return "<pre>\n%s\n</pre>" % result
......@@ -432,14 +434,15 @@ class CiscoCommandShowBgpIPv46Select(ulgmodel.TextCommand):
# not yet in the table body, append before-table section
before = before + l + '\n'
result_len = len(table_lines)
if(table_lines):
table = self._genTable(table_lines,decorator_helper,router)
table = self._genTable(table_lines[resrange:resrange+defaults.range_step],decorator_helper,router)
if(after):
after=decorator_helper.pre(after)
return ulgmodel.TableDecorator(table,table_header_descr,before=decorator_helper.pre(before),
after=after).decorate()
return (ulgmodel.TableDecorator(table,table_header_descr,before=decorator_helper.pre(before),
after=after).decorate(), result_len)
class CiscoCommandShowBgpIPv4NeighAdv(CiscoCommandShowBgpIPv46Select):
......
......@@ -249,8 +249,8 @@ class TextCommand(object):
def rescanHook(self,router):
pass
def decorateResult(self,result,router=None,decorator_helper=None):
return "<pre>\n%s\n</pre>" % result
def decorateResult(self,result,router=None,decorator_helper=None,resrange=None):
return ("<pre>\n%s\n</pre>" % result, len(str.splitlines(result)))
class AnyCommand(TextCommand):
def __init__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment