From 7111ca761df86e4c1892be0b64371368a4107912 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Wed, 3 Mar 2010 18:37:20 +0100 Subject: [PATCH] =?UTF-8?q?[check=5Fmid.py]=20V=C3=A9rification=20et=20nor?= =?UTF-8?q?malisation=20des=20mid=20selon=20le=20plan=20d'adressage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit darcs-hash:20100303173720-ffbb2-3fcf0c07f656aedc7fd61daf7d03e51e96fe841b.gz --- utils/check_mid.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 utils/check_mid.py diff --git a/utils/check_mid.py b/utils/check_mid.py new file mode 100755 index 00000000..9c27276c --- /dev/null +++ b/utils/check_mid.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# CHECK_MID.PY -- Vérification et application de la correspondance mid <-> IP +# +# Copyright (c) 2010 Nicolas Dandrimont +# Authors: Nicolas Dandrimont +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import sys +sys.path.append('/usr/scripts/gestion') + +from midtools import Mid +from ldap_crans import crans_ldap + +from optparse import OptionParser + +def check_mid(normalize): + """Vérifie que les mid correspondent bien aux IP. + + Si normalize = True, modifie la base pour que la correspondance + soit bien vérifiée""" + cl = crans_ldap() + + counter = 0 + s = cl.search("ipHostNumber=*") + for m in s["machine"]: + counter += 1 + mid = int(m.id()) + ip = m.ip() + try: + mid_t = Mid(ipv4=ip) + except ValueError, e: + print e + else: + if mid != int(mid_t): + print "%s: %s!=%s" % (m.Nom(), mid, int(mid_t)) + if normalize: + m.conn.rename_s(m.dn, "%s=%d" % (m.idn, mid_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") + + (options, args) = parser.parse_args() + + check_mid(options.normalize)