From 78b289e130582710498fe11f6f77264dce4ea9fc Mon Sep 17 00:00:00 2001 From: cohen Date: Sat, 7 Oct 2006 02:52:09 +0200 Subject: [PATCH] nettoyage + threading plus propre darcs-hash:20061007005209-f6463-72a15b48ee8b83826945ff33b154e89122995e31.gz --- gestion/tools/locate-mac.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gestion/tools/locate-mac.py b/gestion/tools/locate-mac.py index 2ab0fb74..be2e0601 100755 --- a/gestion/tools/locate-mac.py +++ b/gestion/tools/locate-mac.py @@ -16,11 +16,11 @@ def format_mac(unformated_mac): # classe d'interrogation des switchs class interroge_switch (threading.Thread) : - def __init__ (self, tableau, switch, mac = None) : + def __init__ (self, switch, mac = None) : threading.Thread.__init__(self) - self.tableau=tableau self.switch = switch self.mac = mac + self.reponse=None self.start() def run (self) : @@ -30,8 +30,8 @@ class interroge_switch (threading.Thread) : while (prise==None) & (iteration > 0): prise = sw.where_is_mac(self.mac) iteration = iteration-1 - if prise != None : - self.tableau.append("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise))) + if (prise != None) & (prise != 50) : # si port 50 (uplink, on affiche rien) + self.reponse = ("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise))) # interrogation des switchs en parallele def get_trace(mac): @@ -39,15 +39,21 @@ def get_trace(mac): tableau=[] for switch in ['backbone'] + all_switchs(): - interroge_switch(tableau,switch, mac) + tableau.append(interroge_switch(switch, mac)) while len(threading.enumerate()) > 1 : sleep(1) resultat ='tracage de %s\n' % mac - resultat += '\n'.join(tableau) - return resultat + tracage='' + for t in tableau: + if t.reponse: + tracage += t.reponse +"\n" + if tracage=='': + tracage = "mac inconnue des switchs" + + return (resultat + tracage) # on interroge les switchs et on fait un whos sur la mac if __name__ == '__main__':