printing: afficher constructeur de la mac

Killer feature ;o
This commit is contained in:
Daniel STAN 2014-02-17 18:36:24 +01:00
parent 6fffbd7bd3
commit ff62cda2af
2 changed files with 17 additions and 1 deletions

View file

@ -71,6 +71,21 @@ def telephone(l):
tel.append(t)
return tel
_ethercodes = None
def const_of_mac(mac):
global _ethercodes
if not _ethercodes:
_ethercodes = dict()
with open('/usr/scripts/gestion/ethercodes.dat', 'r') as f:
# Évite de mettre en RAM tout de suite, on utilise un itérateur
for line in iter(f.readline, ''):
line = line.split('\t\t')
_ethercodes[line[0][0:8].lower()] = line[-1].strip()
try:
return mac + u" (%s)" % _ethercodes[mac[0:8]]
except KeyError:
return mac
templateEnv=None
def template():
global templateEnv
@ -87,6 +102,7 @@ def template():
templateEnv.filters['timeformat'] = timeformat
templateEnv.filters['split'] = split
templateEnv.filters['telephone'] = telephone
templateEnv.filters['const_of_mac'] = const_of_mac
templateEnv.filters['tableau'] = tableau
return templateEnv

View file

@ -2,7 +2,7 @@
{% if o.hostAlias %}
{{"Alias : "|coul('gras')}}{{o.hostAlias|join(', ')}}
{% endif %}
{{"MAC : "|coul('gras')}}{{o.macAddress|join(', ')}}
{{"MAC : "|coul('gras')}}{{o.macAddress|join(', ')|const_of_mac}}
{{"IPv4 : "|coul('gras')}}{{o.ipHostNumber|join(', ')}}
{{"IPv6 : "|coul('gras')}}{{o.ip6HostNumber|join(', ')}}
{{"DnsIpv6 : "|coul('gras')}}{% if not o.dnsIpv6 or o.dnsIpv6.0.value %}