From 99d864b81c731cc71938c48fcf7ee3dd8f0d1489 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Sun, 2 Mar 2014 00:28:15 +0100 Subject: [PATCH] pour les macs et u'' si pas d'ipv6 --- crans_utils.py | 8 +++++++- lc_ldap.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crans_utils.py b/crans_utils.py index 64ae861..15a6a95 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -134,7 +134,10 @@ def ip6_of_mac(mac, rid): # En théorie, format_mac est inutile, car on ne devrait avoir # que des mac formatées. - mac = format_mac(mac).replace(u':', u'') + mac = format_mac(mac) + if mac == u'': + return u'' + mac = mac.replace(u':', u'') # hex retourne un str, donc on concatène, suivant la RFC euid64v6 = hex(int(mac[:2], 16)^0b00000010) + mac[2:6] + u'fffe' + mac[6:12] @@ -183,6 +186,9 @@ def format_mac(mac): Transforme une adresse pour obtenir la forme xx:xx:xx:xx:xx:xx Retourne la mac formatée. """ + mac = unicode(mac).lower() + if mac == u'': + return mac mac = netaddr.EUI(mac) if not mac: raise ValueError(u"MAC nulle interdite\nIl doit être possible de modifier l'adresse de la carte.") diff --git a/lc_ldap.py b/lc_ldap.py index b0fd73c..98c3e7f 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -309,7 +309,9 @@ class lc_ldap(ldap.ldapobject.LDAPObject, object): # La machine peut-elle avoir une ipv4 ? if 'v6' not in realm: uldif['ipHostNumber'] = [ unicode(crans_utils.ip4_of_rid(int(rid[0]))) ] - uldif['ip6HostNumber'] = [ unicode(crans_utils.ip6_of_mac(uldif['macAddress'][0], int(rid[0]))) ] + + ip6 = unicode(crans_utils.ip6_of_mac(uldif['macAddress'][0], int(rid[0]))) + uldif['ip6HostNumber'] = [ ip6 ] if ip6 else [] # Mid uldif['mid'] = [ unicode(self._find_id('mid', lockId=lockId)) ]