[gen_confs/switchs.py] récupère la première ligne de la conf sur le switch
Ignore-this: d7af1b8e7e7ae6c903dfe38336dd3f01 darcs-hash:20090302144819-bd074-fef8f13a7b94c0f88e5fbb96c77ffb7078295c5d.gz
This commit is contained in:
parent
8905c9ca16
commit
cfb77c932a
1 changed files with 24 additions and 11 deletions
|
@ -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 <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "%s [-g|--get-conf] <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||
print "Génération du fichier de configuration des switchs donnés."
|
||||
sys.exit(255)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue