[Scripts] On rajoute un champ rid qui fait le lien avec les plages d'ip, et on rend le mid strictement croissant.
Ignore-this: 199e9ff5f09e1fe600c1066179f4e47b Ce patch est un test, il ne restera en prod que si ça fonctionne. L'idée est qu'on souhaiterait conserver les vieilles machines comme les vieux adhérents, sauf demande explicite de suppression, par ailleurs, l'association mid <=> ip est très utile pour pas mal de choses. Pour la conserver, on crée un identifiant rid, qui supplante le mid, qui est lui choisi comme l'aid ou le fid, en incrémentant. Ce patch vise à implémenter cela. S'il génère des bugs, il subira un rollback. darcs-hash:20130123021650-b6762-347428d75f066f7f4821ca067d8c9bb6a4396bf5.gz
This commit is contained in:
parent
70f5ff906a
commit
2a7dd72069
9 changed files with 150 additions and 138 deletions
|
@ -1,10 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
#
|
||||
# CHECK_MID.PY -- Vérification et application de la correspondance mid <-> IP
|
||||
# CHECK_RID.PY -- Vérification et application de la correspondance rid <-> IP
|
||||
#
|
||||
# Copyright (c) 2010 Nicolas Dandrimont
|
||||
# Authors: Nicolas Dandrimont <olasd@crans.org>
|
||||
# Adapté par Pierre-Elliott Bécue pour cause de changement de schéma.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -22,13 +23,13 @@
|
|||
import sys
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
|
||||
from midtools import Mid
|
||||
from ridtools import Rid
|
||||
from ldap_crans import crans_ldap
|
||||
|
||||
from optparse import OptionParser
|
||||
|
||||
def check_mid(normalize):
|
||||
"""Vérifie que les mid correspondent bien aux IP.
|
||||
def check_rid(normalize):
|
||||
"""Vérifie que les rid correspondent bien aux IP.
|
||||
|
||||
Si normalize = True, modifie la base pour que la correspondance
|
||||
soit bien vérifiée"""
|
||||
|
@ -38,24 +39,24 @@ def check_mid(normalize):
|
|||
s = cl.search("ipHostNumber=*")
|
||||
for m in s["machine"]:
|
||||
counter += 1
|
||||
mid = int(m.id())
|
||||
rid = int(m.rid())
|
||||
ip = m.ip()
|
||||
try:
|
||||
mid_t = Mid(ipv4=ip)
|
||||
rid_t = Rid(ipv4=ip)
|
||||
except ValueError, e:
|
||||
print e
|
||||
else:
|
||||
if mid != int(mid_t):
|
||||
print "%s: %s!=%s" % (m.Nom(), mid, int(mid_t))
|
||||
if rid != int(rid_t):
|
||||
print "%s: %s!=%s" % (m.Nom(), rid, int(rid_t))
|
||||
if normalize:
|
||||
m.conn.rename_s(m.dn, "%s=%d" % (m.idn, mid_t))
|
||||
m.rid(int(rid_t))
|
||||
print counter
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = OptionParser()
|
||||
parser.set_defaults(normalize=False)
|
||||
parser.add_option("-n", "--normalize", action="store_true", help="Modifie les mid pour les faire conformer au schema")
|
||||
parser.add_option("-n", "--normalize", action="store_true", help="Modifie les rid pour les faire conformer au schema")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
check_mid(options.normalize)
|
||||
check_rid(options.normalize)
|
Loading…
Add table
Add a link
Reference in a new issue