diff --git a/gestion/ip6tools.py b/gestion/ip6tools.py index 58575b9d..01c2db61 100644 --- a/gestion/ip6tools.py +++ b/gestion/ip6tools.py @@ -24,7 +24,11 @@ import netaddr def mac_to_ipv6(ipv6_prefix, mac_address): """Convert a MAC address (EUI48) to an IPv6 (prefix::EUI64).""" + if mac_address == '': + return '' + if type(mac_address) in [str, unicode]: + mac_address = netaddr.EUI(mac_address) addr = int(mac_address.bits(netaddr.mac_bare), 2) ip6addr = (((addr >> 24) ^ (1 << 17)) << 40) | (0xFFFE << 24) | (addr & 0xFFFFFF) n = netaddr.IPNetwork(ipv6_prefix) diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 236a2fe7..c1d9a768 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -223,6 +223,9 @@ def format_mac(mac): Le séparateur original peut être :, - ou rien Retourne la mac formatée. """ + mac = mac.strip() + if mac == '': + return mac l, mac = preattr(mac) mac = mac.strip().replace(' ','').replace("-", ":") if mac.count(":") == 5: @@ -2863,6 +2866,10 @@ class Machine(BaseClasseCrans): mac = format_mac(mac) + if mac == '': + multi_ok = True + lock = False + # La MAC serait-elle une MAC à la con ? if mac == "00:04:4b:80:80:03": raise ValueError(u"Il s'agit de l'unique adresse MAC achetée par nVidia pour ses cartes réseau. Il faut changer cette adresse.", 2) @@ -2898,7 +2905,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) try: self._set('macAddress', [mac]) if net.size > 1: - self.ipv6(ip6tools.mac_to_ipv6(net, netaddr.EUI(mac)), lock) + self.ipv6(ip6tools.mac_to_ipv6(net, mac), lock) else: self.ipv6(config.ipv6_machines_speciales[int(self.rid())], lock) except Exception as e: @@ -3390,7 +3397,14 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) """Retourne l'adresse IPv6 correspondant à la machine""" if ipv6 == None: - return netaddr.IPAddress(self._data.get('ip6HostNumber', [''])[0]) + if self._data.get('ip6HostNumber', []) == []: + return None + else: + return netaddr.IPAddress(self._data.get('ip6HostNumber')[0]) + + if ipv6 == '': + self._set('ip6HostNumber', []) + return ipv6 = str(ipv6) net = self.netv6() diff --git a/gestion/whos.py b/gestion/whos.py index a03d141e..f6a6f5ec 100755 --- a/gestion/whos.py +++ b/gestion/whos.py @@ -670,7 +670,8 @@ 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 machine.ipv6() != None: + 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"