Amlioration de la lisibilit.

darcs-hash:20070928133838-68412-9f7147534d8da0bbe861c4946b4a668291991b65.gz
This commit is contained in:
glondu 2007-09-28 15:38:38 +02:00
parent 3d624f7347
commit f910406096

View file

@ -10,7 +10,8 @@ sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap
import whos
from annuaires import reverse, all_switchs
from hptools import hpswitch
from hptools import hpswitch, ConversationError
from affich_tools import coul, cprint
# mise en forme d'une adresse mac
def format_mac(unformated_mac):
@ -32,7 +33,10 @@ class interroge_switch (threading.Thread) :
prise = None
iteration = 3
while (prise==None) & (iteration > 0):
prise = sw.where_is_mac(self.mac)
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)
@ -66,8 +70,6 @@ def trace_machine(mac, affiche_uplinks=False):
for t in tableau:
t.join()
resultat = u'Traçage de %s...\n' % mac
tracage = u''
for t in tableau:
if t.reponse:
@ -75,12 +77,13 @@ def trace_machine(mac, affiche_uplinks=False):
if tracage == u'':
tracage = u"Adresse MAC inconnue des switchs\n"
return (resultat + tracage)
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)