[ldap_crans + whos] Ajout de la gestion ipv6

This commit is contained in:
Pierre-Elliott Bécue 2013-02-22 16:08:59 +01:00
parent 9b8bad1610
commit b32363a3ef
2 changed files with 43 additions and 21 deletions

View file

@ -350,7 +350,7 @@ class CransLdap:
# Champs de recherche pour la recherche automatique
auto_search_machines_champs = \
['macAddress', 'host', 'ipHostNumber', 'hostAlias']
['macAddress', 'host', 'ipHostNumber', 'ip6HostNumber', 'hostAlias']
auto_search_champs = { \
'adherent': \
@ -482,7 +482,7 @@ class CransLdap:
aid $ chbre $ mail $ mailAlias $ canonicalAlias $
mid $ rid $ macAddress $ host $ hostAlias $ ipHostNumber $
gpgFingerprint
ip6HostNumber $ gpgFingerprint
Retourne le dn du lock
"""
@ -1188,8 +1188,9 @@ class BaseClasseCrans(CransLdap):
for champ in ['chbre', 'nom', 'prenom', 'mail', 'tel',
'rewriteMailHeaders', 'contourneGreylist',
'puissance', 'canal', 'prise', 'responsable',
'macAddress', 'ipHostNumber', 'host', 'positionBorne',
'derniereConnexion', 'hotspot', 'dnsIpv6', 'machineAlias']:
'macAddress', 'ipHostNumber', 'ip6HostNumber',
'host', 'positionBorne', 'derniereConnexion',
'hotspot', 'dnsIpv6', 'machineAlias']:
if champ in self.modifs:
if champ not in self._init_data.keys():
valeur_initiale = 'N/A'
@ -2855,8 +2856,14 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3)
# Lock de la mac
self.lock('macAddress', mac)
try:
self._set('macAddress', [mac])
if self.netv6() != 'special':
self.ipv6(ip6tools.mac_to_ipv6(self.netv6(), netaddr.EUI(mac)))
else:
self.ipv6(config.ipv6_machines_speciales[int(self.rid())])
except:
raise ValueError('La correspondance MAC <-> EUID64 a planté. Tapez PEB et son entourage.')
return mac
def __host_alias(self, champ, new):
@ -3335,23 +3342,37 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3)
def netv6(self):
"""Retourne le réseau IPv6 Cr@ns associé à la machine"""
classe = {
"crans.org": "fil",
"ferme.crans.org": "fil",
"adm.crans.org": "adm",
"wifi.crans.org": "wifi"
}.get(self.Nom().split('.', 1)[1], "fil")
return netaddr.IPNetwork(config.prefix[classe][0])
for ty, (start, end) in config.rid.iteritems():
if start <= int(self.rid()) <= end:
nettype = ty
break
else:
raise ValueError('Impossible d\'identifier le type de machine.')
def ipv6(self):
if nettype != 'special':
return netaddr.IPNetwork(config.prefix[nettype][0])
else:
return 'special'
def ipv6(self, ipv6=None):
"""Retourne l'adresse IPv6 correspondant à la machine"""
if ipv6 == None:
return unicode(self._data.get('ip6HostNumber', [''])[0])
ipv6 = str(ipv6)
net = self.netv6()
if self.machineAlias():
return netaddr.IPAddress(net.first + int(self.id()))
if net == 'special':
ipv6_t = config.ipv6_machines_speciales[int(self.rid())]
else:
return ip6tools.mac_to_ipv6(net, netaddr.EUI(self.mac()))
ipv6_t = str(ip6tools.mac_to_ipv6(net, netaddr.EUI(self.mac())))
if ipv6 != ipv6_t:
raise ValueError('L\'ipv6 n\'est pas celle EUID64 attendue. %s, %s' % (ipv6, ipv6_t))
self.lock('ip6HostNumber', ipv6)
self._set('ip6HostNumber', [ipv6])
def nom6(self):
"""Retourne le nom "ipv6" de la machine"""

View file

@ -338,12 +338,12 @@ def list_machines(machines) :
t, bl = __bases_machines(m)
# Données
data.append([m.id(), t, m.nom().split('.')[0], m.ip(), m.mac(), bl])
data.append([m.id(), m.rid(), t, m.nom().split('.')[0], m.ip(), m.ipv6(), m.mac(), bl])
return tableau(data,
titre = [u'mid', u'Type', u'Nom de machine', u'Adresse IP', u'Adresse MAC', u'Limitation'],
largeur = [5, 4, '*', 17, 19, 10],
alignement = ['d', 'c', 'c', 'c', 'c', 'c'])
titre = [u'mid', u'rid', u'Type', u'Nom de machine', u'Adresse IP', u'Adresse IPv6', u'Adresse MAC', u'Limitation'],
largeur = [5, 5, 4, '*', 24, 17, 19, 10],
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c'])
def list_bornes(bornes) :
"""
@ -609,6 +609,7 @@ def machine_details(machine) :
f+= coul(u'IP : ','gras') + "%s\t\t" %machine.ip()
f+= coul(u'MAC : ','gras') + "%s\n" %machine.mac()
f+= coul(u'IPv6 : ','gras') + "%s\n" %machine.ipv6()
if len(machine.sshFingerprint()) > 0 and aff_ssh:
f += u"\n".join([coul(u'Fingerprint SSH : ', 'gras') + u"%s" % (i) for i in machine.sshFingerprint()])+"\n"