Commit 726d99d1 authored by Tomas Hlavacek's avatar Tomas Hlavacek

Add IP address annotation for BIRD and Cisco.

IP address annotation (clickable modal window/href) in the show bgp
ipv4/6 unicas <prefix> output added.

In future it should be linked via decorator_helper to whois client /
DNS resolver to give more meaningful explanation of observed network
topology.
parent eef766c2
......@@ -38,6 +38,9 @@ import defaults
import ulgmodel
IPV4_ANNOTATE_REGEXP = '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(/[0-9]{1,2})?)'
ipv4_annotate_regexp = re.compile(IPV4_ANNOTATE_REGEXP)
### CGI output handler
class Session(object):
......@@ -307,9 +310,28 @@ class DecoratorHelper:
def decorateASN(self,asn,prefix="AS"):
return self.mwin(defaults.getASNURL(str(asn)),prefix+str(asn))
def decorateIP(self,ip):
def decoratePrefix(self,ip):
return self.mwin(defaults.getIPPrefixURL(ip),ip)
def annotatePrefixes(self,line):
s=0
r=''
for m in ipv4_annotate_regexp.finditer(line):
r = r + line[s:m.start()]
r = r + self.decoratePrefix(line[m.start():m.end()])
s = m.end()
return r + line[s:]
def annotateIPs(self,line):
s=0
r=''
for m in ipv4_annotate_regexp.finditer(line):
r = r + line[s:m.start()]
r = r + self.decoratePrefix(line[m.start():m.end()])
s = m.end()
return r + line[s:]
class ULGCgi:
def __init__(self):
......
......@@ -249,7 +249,7 @@ class BirdShowRouteCommand(ulgmodel.TextCommand):
if(ml):
# generate table content
result.append([
(decorator_helper.decorateIP(ml[0]),),
(decorator_helper.decoratePrefix(ml[0]),),
(ml[1],),
(ml[2],),
(ml[3],),
......@@ -317,9 +317,9 @@ class BirdShowRouteAllCommand(ulgmodel.TextCommand):
for asn in ases:
r = r + decorator_helper.decorateASN(asn,prefix='')
r = r + ' '
return r
return decorator_helper.annotateIPs(r)
else:
return l
return decorator_helper.annotateIPs(l)
s = str.splitlines(session.getResult())
......
......@@ -502,7 +502,7 @@ class CiscoCommandShowBgpIPv46Select(ulgmodel.TextCommand):
# generate table content
result.append([
(ml[0],),
(decorator_helper.decorateIP(ml[1]),),
(decorator_helper.decoratePrefix(ml[1]),),
(ml[2],),
(ml[3],),
(ml[4],),
......@@ -637,9 +637,9 @@ class CiscoShowBgpIPv46Uni(ulgmodel.TextCommand):
if(asn != ases[-1]):
r = r + ' '
r = r + m.group(3)
return r
return decorator_helper.annotateIPs(r)
else:
return l
return decorator_helper.annotateIPs(l)
s = str.splitlines(session.getResult())
......
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