From d31dc13990d9f67ace100c81134f596dbbb56347 Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Fri, 27 Apr 2012 00:34:25 +0200 Subject: [PATCH] =?UTF-8?q?[switchs.py]=20Choix=20du=20header=20=20=C3=A0?= =?UTF-8?q?=20partir=20de=20ldap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En réalité, il y a un soucis: il faudrait rajouter la lettre de révision dans les données enregistrées... darcs-hash:20120426223425-28565-8b1951cd8b91ff374045b20f42f54445b125bc25.gz --- gestion/gen_confs/switchs.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/gestion/gen_confs/switchs.py b/gestion/gen_confs/switchs.py index 820c5e5c..daf2dd59 100644 --- a/gestion/gen_confs/switchs.py +++ b/gestion/gen_confs/switchs.py @@ -24,6 +24,16 @@ from random import shuffle from gen_confs import * from time import localtime import config +import re + +capture_model = re.compile(r'\((.*)\)') +headers_by_model = { +'HP 2626': '; J4900C Configuration Editor; Created on release #H.10.83', +'HP 2650': '; J4899B Configuration Editor; Created on release #H.10.83', +'HP 2810-24G':'; J9021A Configuration Editor; Created on release #N.11.25', +'HP 2610-24':'; J9085A Configuration Editor; Created on release #R.11.54', +'HP 2610-48':'; J9088A Configuration Editor; Created on release #R.11.54', +'HP 2910al-24G':'; J9145A Configuration Editor; Created on release #W.14.38'} try: any @@ -288,6 +298,11 @@ exit self.aff.cycle() options = [ opt for opt,arg in opts] + + # IP + machine = self.db.search(switch)['machine'][0] + params['ip'] = str(machine.ip()) + if '-g' in options or '--get-conf' in options: old_config = NamedTemporaryFile() res, msg = commands.getstatusoutput("scp bat%s-%i:cfg/startup-config %s" % (bat, sw_num, old_config.name)) @@ -305,7 +320,14 @@ exit params['switch_config_header'] = arg break else: - params['switch_config_header']= '; J4899A Configuration Editor; Created on release #H.10.50' + try: + match = capture_model.search(machine.info()[0]) + model = match.group(1) + sys.stderr.write(model) + params['switch_config_header']=headers_by_model[model] + except: + sys.stderr.write('Impossible de déterminer le header à utiliser (switch %s)' % switch) + params['switch_config_header']= '; J4899A Configuration Editor; Created on release #H.10.50' model = params['switch_config_header'].split(' ', 2)[1] if model == "J9145A": @@ -313,10 +335,6 @@ exit else: params['module-type'] = '' - # IP - machine = self.db.search(switch)['machine'][0] - params['ip'] = str(machine.ip()) - self.aff.cycle() # Nombre de prises et modèle