From 2838a60501602bbb147906885ceb2a4d1d997341 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 4 Jun 2015 23:25:39 +0200 Subject: [PATCH] On ajoute une option bornev6, c'est zoli, et on previent la nounou qui ajoute une machine v6 only --- gestion/gest_crans.py | 26 ++++++++++++++++++++++++-- gestion/ldap_crans.py | 17 ++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/gestion/gest_crans.py b/gestion/gest_crans.py index e8a96362..fdfa70a1 100755 --- a/gestion/gest_crans.py +++ b/gestion/gest_crans.py @@ -1922,10 +1922,24 @@ def set_machine(machine): err += c.args[0] + '\n' except EnvironmentError, c: err += c.args[0] + '\n' - try: machine.ip(result[2]) except ValueError, c: - err += c.args[0] + '\n' + if len(c.args)>1 and c.args[1] == 1 and isadm: + arg = u'--title "Plage d\'ip" ' + arg += u'--yesno "La machine va être ajoutée en v6 only, continuer ? \n" 0 0' + no, res = dialog(arg) + if no: + return set_machine(machine) + else: + try: machine.ip(result[2], lock=True, force=True) + except EnvironmentError, c: + err += c.__str__() + '\n' + except RuntimeError, c: + err += c.args[0] + '\n' # Plus d'IP libres, peut-être à traiter differement ? + except ValueError, c: + err += c.args[0] + '\n' + else: + err += c.args[0] + '\n' except EnvironmentError, c: err += c.__str__() + '\n' except RuntimeError, c: @@ -2616,6 +2630,7 @@ def menu_principal(): if isadm: arg += u'"aKM" "Ajouter une machine à l\'association" "" ' arg += u'"aKB" "Ajouter une borne wifi" "" ' + arg += u'"aKB6" "Ajouter une borne wifi v6" "" ' annul, result = dialog(arg) if annul: break @@ -2732,6 +2747,13 @@ def menu_principal(): if set_machine(becane): becane.restore() + elif choix == 'aKB6': + # Ajout borne wifi v6 + becane = BorneWifi(AssociationCrans(db.conn)) + becane.bornev6 = ['True'] + if set_machine(becane): + becane.restore() + ############################################## if choix == 'aMc': diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index ffd2f31e..5a9ac609 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -3228,7 +3228,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) self._set('sshFingerprint', liste) return liste - def ip(self, ip=None, lock=True): + def ip(self, ip=None, lock=True, force=False): """ Défini ou retourne l'IP de la machine. Les IP sont stoquées sous forme xxx.xxx.xxx.xxx et doivent être fournies ainsi. @@ -3245,14 +3245,18 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) l, ip = preattr(ip) - # Dans quel sous réseau se trouve le rid? if isinstance(self, MachineWifi): mach_type = u'wifi-adh' plage_rid = config.rid_primaires['wifi-adh'] + # Si on ajoute une bornv6, on prend dans la plage v6 only elif isinstance(self, BorneWifi): mach_type = u'bornes' - plage_rid = config.rid_primaires['bornes'] + try: + if self.bornev6: + plage_rid = config.rid_primaires['bornes-v6'] + except AttributeError: + plage_rid = config.rid_primaires['bornes'] elif isinstance(self.proprietaire(), AssociationCrans): mach_type = u'crans' plage_rid = config.rid_primaires['serveurs'] @@ -3277,13 +3281,13 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) int(elem[1]['rid'][0]) for elem in self.conn.search_ext_s(self.base_dn, ldap.SCOPE_SUBTREE, "(&(rid>=%s)(rid<=%s))" % (plage[0], plage[1])) ] - #print sorted(rid_pris) # Par defaut la plage est pas v6 (cf bornes/bornes v6) - v6 = False for rid in xrange(plage[0], plage[1] + 1): if rid not in rid_pris: # On verifie que l'ip se termine pas par 0 ou 255 et que il y a une ipv4 dispo (on sort si on est dans une plage v6) if not ridtools.Rid(rid=rid).ipv4_dispo: + if not force: + raise ValueError(u"La machine sera v6 only", 1) v6 = True break # On vire les ip qui se terminent par 0 ou 255 (toutes, thanks windows) @@ -3301,6 +3305,9 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) elif ip == '': self._set('ipHostNumber', []) ip = None + + + # Si il y a deja une ip, on controle qu'elle correspond bien à son rid elif ip != '': # L'ip est elle dans le bon sous-réseau ? # (accessoirement teste si l'IP est valide et ne correspond pas