diff --git a/gestion/gen_confs/switchs.py b/gestion/gen_confs/switchs.py index b2cc258a..327fd97e 100755 --- a/gestion/gen_confs/switchs.py +++ b/gestion/gen_confs/switchs.py @@ -14,7 +14,7 @@ Dans tous les cas FAIRE LE SNMP A LA MAIN (script hpttols) """ -import string, sys, os, commands, smtplib, tempfile +import string, sys, os, commands, smtplib, tempfile, getopt sys.path.append('/usr/scripts/gestion') from hptools import hpswitch, sw_chbre @@ -253,28 +253,40 @@ exit # Batiment et numéro du switch bat = switch[3].lower() sw_num = int(switch[5]) - old_config = NamedTemporaryFile() - res, msg = commands.getstatusoutput("scp bat%s-%i:cfg/startup-config %s" % (bat, sw_num, old_config.name)) - - if not res: - raise RuntimeError(u"Erreur : impossible de récupérer l'ancienne configuration du switch") - - params['switch_config_header'] = old_config.readline() - old_config.close() - # Conf radius sys.path.append('/usr/scripts/gestion/secrets') from secrets import radius_key + + self.aff.cycle() + shuffle(self.rad_servs) rad = self.rad_template * len(self.rad_servs) params = { 'switch' : switch, 'bat' : bat.upper() , 'radius_key' : radius_key , 'radius-serveurs' : rad[:-1] % tuple(self.rad_servs)} + self.aff.cycle() + + if '-g' in opts or '--get-conf' in opts: + old_config = NamedTemporaryFile() + res, msg = commands.getstatusoutput("scp bat%s-%i:cfg/startup-config %s" % (bat, sw_num, old_config.name)) + + if not res: + raise RuntimeError(u"Erreur : impossible de récupérer l'ancienne configuration du switch") + + params['switch_config_header'] = old_config.readline() + old_config.close() + + self.aff.cycle() + else: + params['switch_config_header']= '; J4899A Configuration Editor; Created on release #H.10.50' + # IP machine = self.db.search(switch)['machine'][0] params['ip'] = str(machine.ip()) + self.aff.cycle() + # Nombre de prises et modèle nb_prises = machine.nombrePrises() if nb_prises < 0 : @@ -474,8 +486,9 @@ aaa port-access mac-based %(prise)s unauth-vid 1 fd.close() if __name__ == '__main__' : + opts, args = getopt.getopt(sys.argv[1:], 'hga', ['get-conf', 'help']) if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 1 : - print "%s " % sys.argv[0].split('/')[-1].split('.')[0] + print "%s [-g|--get-conf] " % sys.argv[0].split('/')[-1].split('.')[0] print "Génération du fichier de configuration des switchs donnés." sys.exit(255)