From d5bfd8d00415f2a4928176c1a0e35bad824e7aa9 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sun, 12 Sep 2010 15:33:33 +0200 Subject: [PATCH] [locate-mac] Suppression (utiliser locate_mac) darcs-hash:20100912133333-ffbb2-8055885fee4aa48b40bc49a67077b2f920bbd647.gz --- gestion/tools/locate-mac.py | 90 ------------------------------------- respbats/locate-mac | 2 +- 2 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 gestion/tools/locate-mac.py diff --git a/gestion/tools/locate-mac.py b/gestion/tools/locate-mac.py deleted file mode 100644 index efc20b84..00000000 --- a/gestion/tools/locate-mac.py +++ /dev/null @@ -1,90 +0,0 @@ -#! /usr/bin/env python -# -*- coding: iso-8859-15 -*- - -import sys, re -from time import sleep -from os import system -import threading - -sys.path.append('/usr/scripts/gestion') -from ldap_crans import crans_ldap -import whos -from annuaires import reverse, all_switchs -from hptools import hpswitch, ConversationError -from affich_tools import coul, cprint - -# mise en forme d'une adresse mac -def format_mac(unformated_mac): - return str(":".join([i.zfill(2) for i in unformated_mac.split(":")]).lower()) - - -# classe d'interrogation des switchs -class interroge_switch (threading.Thread) : - def __init__ (self, switch, mac=None, affiche_uplinks=False): - threading.Thread.__init__(self) - self.switch = switch - self.mac = mac - self.reponse = None - self.affiche_uplinks = affiche_uplinks - self.start() - - def run (self) : - sw = hpswitch(self.switch) - prise = None - iteration = 3 - while (prise==None) & (iteration > 0): - try: - prise = sw.where_is_mac(self.mac) - except ConversationError: - self.reponse = coul("Impossible de communiquer avec %s !" % self.switch, "jaune") - iteration = iteration-1 - if (prise != None): - nom=sw.nom(None,prise) - if self.affiche_uplinks or "uplink" not in nom: - self.reponse = ("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), nom)) - - -# Retourne les infos sur la machine (l'équivalent d'un whos, mais renvoie la -# chaîne de caractères) -def info_machine(mac): - s = [] - db = crans_ldap() - machines = db.search("mac=%s" % mac)['machine'] - color_re = re.compile('\x1b\[1;([0-9]|[0-9][0-9])m') - for m in machines: - r = whos.machine_details(m) - # On supprime les couleurs - r = color_re.sub('', r) - s.append(r) - if len(machines) == 0: - s.append(u"Recherche LDAP de la MAC %s : aucune machine trouvée\n" % mac) - return u"\n".join(s) - - -# interrogation des switchs en parallele -def trace_machine(mac, affiche_uplinks=False): - tableau = [] - - for switch in ['backbone','multiprise-v6'] + all_switchs(): - tableau.append(interroge_switch(switch, mac, affiche_uplinks)) - - for t in tableau: - t.join() - - tracage = u'' - for t in tableau: - if t.reponse: - tracage += t.reponse + u"\n" - if tracage == u'': - tracage = u"Adresse MAC inconnue des switchs\n" - - return tracage - - -# on interroge les switchs et on fait un whos sur la mac -if __name__ == '__main__': - mac = format_mac(sys.argv[1]) - affiche_uplinks = len(sys.argv) > 2 and bool(sys.argv[2]) - cprint(u'Traçage de %s...\n' % mac, "rouge") - print trace_machine(mac, affiche_uplinks) - print system('/usr/scripts/gestion/whos.py -a mac=%s' % mac) diff --git a/respbats/locate-mac b/respbats/locate-mac index dfa2611d..9d74c32a 100755 --- a/respbats/locate-mac +++ b/respbats/locate-mac @@ -1,4 +1,4 @@ #!/bin/sh #execution avec des droits suffisants -LANG=fr_FR@euro sudo -u '#120' /usr/scripts/gestion/tools/locate-mac.py $* +LANG=fr_FR@euro sudo -u '#120' /usr/scripts/gestion/tools/locate_mac.py $*