From 97b1db8a56b3115f5a28601e8a5a239cd523c8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Thu, 30 May 2013 01:50:21 +0200 Subject: [PATCH] [ridtools] Oubli de modif par rapport aux rids --- gestion/ridtools.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gestion/ridtools.py b/gestion/ridtools.py index d08a2b94..1be49e8b 100644 --- a/gestion/ridtools.py +++ b/gestion/ridtools.py @@ -23,7 +23,7 @@ # along with this program. If not, see . import netaddr - +import itertools import config class Rid(object): @@ -83,8 +83,8 @@ class Rid(object): self.ipv4_dispo = True self.priv = ip.is_private() - for tp in ['fil', 'adherents', 'wifi', 'adm', 'gratuit', 'personnel-ens', 'serveurs']: - for net in config.NETs[tp]: + for tp in config.NETs_primaires.keys(): + for net in config.NETs_primaires[tp]: if ip in netaddr.IPNetwork(net): self.type = tp break @@ -99,11 +99,12 @@ class Rid(object): else: raise ValueError("%s dans aucun des réseaux gérés par le Cr@ns..." % ip) + ranges = itertools.chain(*[xrange(a, b+1) for (a,b) in config.rid[self.type]]) if not self.rid: - self.rid = config.rid[self.type][0] + ip.value - netaddr.IPNetwork(config.NETs[self.type][0]).value + self.rid = config.rid[self.type][0][0] + ip.value - netaddr.IPNetwork(config.NETs[self.type][0]).value - if self.rid > config.rid[self.type][1]: - raise ValueError("%s trop élevée pour le réseau '%s'" % (ip, self.type)) + if self.rid not in ranges: + raise ValueError("%s trop hors des plages prévues pour le réseau '%s'" % (ip, self.type)) if self.type == 'personnel-ens': self.reste = self.rid & 0xff