diff --git a/gestion/hptools.py b/gestion/hptools.py index 69adea4a..12e4437b 100755 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -217,9 +217,9 @@ class hpswitch : def __scp(self,destination,fichier) : if self.__debug : - self.__logDest.write("HP DEBUG : scp(%s,%s,%s)\n" % (file, self.switch, destination)) - if exists(file): - system('scp %s %s:%s' % (file, self.switch, destination)) + self.__logDest.write("HP DEBUG : scp(%s,%s,%s)\n" % (fichier, self.switch, destination)) + if exists(fichier): + system('scp %s %s:%s' % (fichier, self.switch, destination)) def update(self,file=None) : """ Upload le fichier de config fourni @@ -379,32 +379,44 @@ class sw_chbre(hpswitch) : self.nom(nom) if __name__ == '__main__' : - import sys, getopt + import sys, getopt, sre try : - options, arg = getopt.getopt(sys.argv[1:], 'hs:c:', [ 'help' ]) + options, arg = getopt.getopt(sys.argv[1:], 'U:hc:', [ 'help' ]) except getopt.error, msg : print msg sys.exit(1) - - switchs = [] + cmds = [] + firmware='' for opt, val in options : if opt == '-h' or opt=='--help' : - print "Usage : %s -c commande1 -c commande2... -s switch1 -s switch2..." - print "Envoi les commandes données au switchs dont le nom est fourni" - print "si aucun switch est founi envoi à tous les switchs" + print "Usage : %s [[-c commande1] -c commande2...] [-U firmware] regex " + print "Envoi les commandes données au switchs matchant la regex" print "si aucune commande est founie lit l'entree standart" + print "L'envoi de firmware ne fait pas rebooter le switch" sys.exit(0) - elif opt=='-s' : - switchs.append(val) - elif opt=='-c' : cmds.append(val) - - if not switchs : switchs = all_switchs() - if not cmds : + + elif opt=='-U' : + firmware=val + + # Quels switchs ? + switchs=[] + if arg : + re=sre.compile(arg[0]) + for sw in all_switchs() : + if re.match(sw) : + switchs.append(sw) + + if not switchs : + print "Aucun switch trouvé" + print "Note : il faut une _regex_ (!= wilcards au sens du shell)" + sys.exit(3) + + if not cmds and not firmware : cmds=map(str.strip,sys.stdin.readlines()) # Ce que l'on va faire @@ -412,20 +424,17 @@ if __name__ == '__main__' : print "\nSwitchs : ", ' '.join(switchs) print - sleep(2) + raw_input("Appuyer sur entrée pour continuer") - if arg : - print "ERREUR, argument invalide" - print 'Attention, ne pas oublier les " pour les commandes' - sys.exit(2) - for sw in switchs : print sw - try: + try: # Au cas ou le switch ne répondrai pas s = hpswitch(sw) + if firmware : + s.upgrade(firmware) for cmd in cmds : print s.send_cmd(cmd) except : print 'ERREUR' - +