From 9bf29bf91a62fc673ac7823940409ce906d9d05b Mon Sep 17 00:00:00 2001 From: cohen Date: Thu, 5 Oct 2006 00:57:43 +0200 Subject: [PATCH] recuperation des infos sous la forme d'une string darcs-hash:20061004225743-f6463-04f78a52b1cdda09426ab1bc437a15020e6bedb8.gz --- gestion/tools/locate-mac.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gestion/tools/locate-mac.py b/gestion/tools/locate-mac.py index 5490ab14..cb83c14b 100755 --- a/gestion/tools/locate-mac.py +++ b/gestion/tools/locate-mac.py @@ -16,8 +16,9 @@ def format_mac(unformated_mac): # classe d'interrogation des switchs class interroge_switch (threading.Thread) : - def __init__ (self, switch, mac = None) : + def __init__ (self, tableau, switch, mac = None) : threading.Thread.__init__(self) + self.tableau=tableau self.switch = switch self.mac = mac self.start() @@ -26,19 +27,23 @@ class interroge_switch (threading.Thread) : sw = hpswitch(self.switch) prise = sw.where_is_mac(mac) if prise != None : - print "%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise)) + self.tableau.append("%-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 print_trace(mac): +def get_trace(mac): + + tableau=[] for switch in ['backbone'] + all_switchs(): - interroge_switch(switch, mac) + interroge_switch(tableau,switch, mac) while len(threading.enumerate()) > 1 : sleep(1) + return '\n'.join(tableau) + # on interroge les switchs et on fait un whos sur la mac if __name__ == '__main__': mac = format_mac(sys.argv[1]) - print_trace(mac) + print get_trace(mac) print system('/usr/scripts/gestion/whos.py -a mac=%s' % mac)