[gen_confs/switchs.py] on rajoute le vlan 21
Ignore-this: d035e1792e12a5fedbb2d3e3c055a95d darcs-hash:20090302140835-bd074-9d2311070b88a7bd5ab1dc0a6923274666daebe9.gz
This commit is contained in:
parent
091981f029
commit
eb82b03462
1 changed files with 57 additions and 38 deletions
|
@ -78,8 +78,8 @@ vlan %(vlan_hotspot)s
|
||||||
%(prises_hotspot)s
|
%(prises_hotspot)s
|
||||||
no ip address
|
no ip address
|
||||||
exit
|
exit
|
||||||
vlan %(vlan_radin)s
|
vlan %(vlan_gratuit)s
|
||||||
name "Radin"
|
name "Gratuit"
|
||||||
tagged %(prises_default)s
|
tagged %(prises_default)s
|
||||||
no ip address
|
no ip address
|
||||||
exit
|
exit
|
||||||
|
@ -88,6 +88,11 @@ vlan %(vlan_accueil)s
|
||||||
tagged %(prises_default)s
|
tagged %(prises_default)s
|
||||||
no ip address
|
no ip address
|
||||||
exit
|
exit
|
||||||
|
vlan %(vlan_appts)s
|
||||||
|
name "Appt ENS"
|
||||||
|
%(prises_appts)s
|
||||||
|
no ip address
|
||||||
|
exit
|
||||||
;-------------------------------------------------------- Logs
|
;-------------------------------------------------------- Logs
|
||||||
%(INTERFACES_CONF)s
|
%(INTERFACES_CONF)s
|
||||||
;------------------------------------------------------- Accès d'administration
|
;------------------------------------------------------- Accès d'administration
|
||||||
|
@ -134,7 +139,7 @@ exit
|
||||||
rad_template = "radius-server host %s\n"
|
rad_template = "radius-server host %s\n"
|
||||||
|
|
||||||
def __init__(self,truc):
|
def __init__(self,truc):
|
||||||
""" truc est soit :
|
""" truc est soit :
|
||||||
* une _liste_ de chambres => reconfig de ces chambres
|
* une _liste_ de chambres => reconfig de ces chambres
|
||||||
* un _tulpe_ de noms de switch => reconfig de ces swiths"""
|
* un _tulpe_ de noms de switch => reconfig de ces swiths"""
|
||||||
self.db = crans_ldap() # connexion LDAP
|
self.db = crans_ldap() # connexion LDAP
|
||||||
|
@ -145,10 +150,10 @@ exit
|
||||||
else :
|
else :
|
||||||
self.chbres = None
|
self.chbres = None
|
||||||
self.switch = truc
|
self.switch = truc
|
||||||
|
|
||||||
def __str__(self) :
|
def __str__(self) :
|
||||||
return 'switchs'
|
return 'switchs'
|
||||||
|
|
||||||
def restart(self) :
|
def restart(self) :
|
||||||
if self.chbre :
|
if self.chbre :
|
||||||
# Tout est déja fait
|
# Tout est déja fait
|
||||||
|
@ -156,10 +161,10 @@ exit
|
||||||
####### Vu qu'il n'y a pas de serveur tftp ici
|
####### Vu qu'il n'y a pas de serveur tftp ici
|
||||||
# on excécute pas le truc en dessous
|
# on excécute pas le truc en dessous
|
||||||
#for switch in self.switch :
|
#for switch in self.switch :
|
||||||
# self.aff = anim('\treboot de %s' % switch)
|
# self.aff = anim('\treboot de %s' % switch)
|
||||||
# sw = hptools.switch(switch)
|
# sw = hptools.switch(switch)
|
||||||
# sw.update()
|
# sw.update()
|
||||||
|
|
||||||
def gen_conf(self) :
|
def gen_conf(self) :
|
||||||
if self.chbres :
|
if self.chbres :
|
||||||
self.chbres.sort()
|
self.chbres.sort()
|
||||||
|
@ -168,19 +173,19 @@ exit
|
||||||
elif self.switch :
|
elif self.switch :
|
||||||
for switch in self.switch :
|
for switch in self.switch :
|
||||||
self.configure_switch(switch)
|
self.configure_switch(switch)
|
||||||
|
|
||||||
def configure_chbre(self,chbre) :
|
def configure_chbre(self,chbre) :
|
||||||
""" Recontigure la chambre fournie chambre """
|
""" Recontigure la chambre fournie chambre """
|
||||||
try :
|
try :
|
||||||
bat = chbre[0].lower()
|
bat = chbre[0].lower()
|
||||||
if bat in bat_switchs :
|
if bat in bat_switchs :
|
||||||
prise = sw_chbre(chbre)
|
prise = sw_chbre(chbre)
|
||||||
prise.reconfigure() # Vitesse et nom (juste au cas ou ca aurait changé)
|
prise.reconfigure() # Vitesse et nom (juste au cas ou ca aurait changé)
|
||||||
elif bat in bat_manuels :
|
elif bat in bat_manuels :
|
||||||
class prise_non_manageable :
|
class prise_non_manageable :
|
||||||
def __init__(self,chbre) :
|
def __init__(self,chbre) :
|
||||||
self.chbre = chbre
|
self.chbre = chbre
|
||||||
|
|
||||||
def __mail(self,sujet) :
|
def __mail(self,sujet) :
|
||||||
To = "clef%s@crans.org" % self.chbre[0].lower()
|
To = "clef%s@crans.org" % self.chbre[0].lower()
|
||||||
From = To
|
From = To
|
||||||
|
@ -190,22 +195,22 @@ exit
|
||||||
txt_mail+= "Subject: (CRANS) %s\n\nMerci." % sujet
|
txt_mail+= "Subject: (CRANS) %s\n\nMerci." % sujet
|
||||||
conn.sendmail(From, To , txt_mail % { 'From' : From, 'To' : To })
|
conn.sendmail(From, To , txt_mail % { 'From' : From, 'To' : To })
|
||||||
conn.quit()
|
conn.quit()
|
||||||
|
|
||||||
def disable(self) :
|
def disable(self) :
|
||||||
self.__mail("Chambre %s à débrancher." % self.chbre)
|
self.__mail("Chambre %s à débrancher." % self.chbre)
|
||||||
def enable(self) :
|
def enable(self) :
|
||||||
self.__mail("Chambre %s à brancher." % self.chbre)
|
self.__mail("Chambre %s à brancher." % self.chbre)
|
||||||
|
|
||||||
prise=prise_non_manageable(chbre)
|
prise=prise_non_manageable(chbre)
|
||||||
|
|
||||||
else :
|
else :
|
||||||
# Rien a faire
|
# Rien a faire
|
||||||
print OK
|
print OK
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
a = self.db.search('chbre=%s&paiement=ok' % chbre)
|
a = self.db.search('chbre=%s&paiement=ok' % chbre)
|
||||||
a = a['adherent'] + a['club']
|
a = a['adherent'] + a['club']
|
||||||
if a and 'bloq' not in a[0].blacklist_actif() :
|
if a and 'bloq' not in a[0].blacklist_actif() :
|
||||||
# Il faut activer la prise
|
# Il faut activer la prise
|
||||||
anim('\tactivation chbre %s' % chbre)
|
anim('\tactivation chbre %s' % chbre)
|
||||||
|
@ -214,7 +219,7 @@ exit
|
||||||
# Il faut désactiver la prise
|
# Il faut désactiver la prise
|
||||||
anim('\tdésactivation chbre %s' % chbre)
|
anim('\tdésactivation chbre %s' % chbre)
|
||||||
prise.disable()
|
prise.disable()
|
||||||
|
|
||||||
print OK
|
print OK
|
||||||
except :
|
except :
|
||||||
print ERREUR
|
print ERREUR
|
||||||
|
@ -222,9 +227,9 @@ exit
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def configure_switch(self,switch) :
|
def configure_switch(self,switch) :
|
||||||
self.aff = anim('\tconfiguration de %s' % switch)
|
self.aff = anim('\tconfiguration de %s' % switch)
|
||||||
try:
|
try:
|
||||||
|
@ -254,10 +259,10 @@ exit
|
||||||
from secrets import radius_key
|
from secrets import radius_key
|
||||||
shuffle(self.rad_servs)
|
shuffle(self.rad_servs)
|
||||||
rad = self.rad_template * len(self.rad_servs)
|
rad = self.rad_template * len(self.rad_servs)
|
||||||
params = { 'switch' : switch, 'bat' : bat.upper() ,
|
params = { 'switch' : switch, 'bat' : bat.upper() ,
|
||||||
'radius_key' : radius_key ,
|
'radius_key' : radius_key ,
|
||||||
'radius-serveurs' : rad[:-1] % tuple(self.rad_servs)}
|
'radius-serveurs' : rad[:-1] % tuple(self.rad_servs)}
|
||||||
|
|
||||||
# IP
|
# IP
|
||||||
machine = self.db.search(switch)['machine'][0]
|
machine = self.db.search(switch)['machine'][0]
|
||||||
params['ip'] = str(machine.ip())
|
params['ip'] = str(machine.ip())
|
||||||
|
@ -266,13 +271,13 @@ exit
|
||||||
nb_prises = machine.nombrePrises()
|
nb_prises = machine.nombrePrises()
|
||||||
if nb_prises < 0 :
|
if nb_prises < 0 :
|
||||||
raise RuntimeError("Erreur : impossible de déterminer les caractéristiques du switch.")
|
raise RuntimeError("Erreur : impossible de déterminer les caractéristiques du switch.")
|
||||||
|
|
||||||
### Configuration prises
|
### Configuration prises
|
||||||
params['INTERFACES_CONF'] = ''
|
params['INTERFACES_CONF'] = ''
|
||||||
|
|
||||||
# Dictionnaire prise -> chambre
|
# Dictionnaire prise -> chambre
|
||||||
prise_chbres = reverse(bat)
|
prise_chbres = reverse(bat)
|
||||||
|
|
||||||
# Prises occupées par des machines du Cr@ns
|
# Prises occupées par des machines du Cr@ns
|
||||||
crans_prises={}
|
crans_prises={}
|
||||||
for m in self.db.search('prise=%s%i*' % (bat.upper(), sw_num))['machine'] :
|
for m in self.db.search('prise=%s%i*' % (bat.upper(), sw_num))['machine'] :
|
||||||
|
@ -288,20 +293,24 @@ exit
|
||||||
vlans = { 'wifi_tagged' : [] , 'wifi_untagged' : [] ,
|
vlans = { 'wifi_tagged' : [] , 'wifi_untagged' : [] ,
|
||||||
'hotspot_tagged' : [], 'hotspot_untagged' : [],
|
'hotspot_tagged' : [], 'hotspot_untagged' : [],
|
||||||
'adm_tagged' : [] , 'adm_untagged' : [] ,
|
'adm_tagged' : [] , 'adm_untagged' : [] ,
|
||||||
|
'appts_tagged' : [], 'appts_untagged' : [],
|
||||||
|
|
||||||
# VLans pour le reste: le vlan des adhérents, des
|
# VLans pour le reste: le vlan des adhérents, des
|
||||||
# inconnus et de ceux qui ne paie pas
|
# inconnus et de ceux qui ne paie pas
|
||||||
'default' : [] }
|
'default' : [] }
|
||||||
|
|
||||||
|
personnels_loges = self.db.search('etudes=Personnel ENS')['adherent']
|
||||||
|
prises_appartements= [ p.chbre() for p in personnels_loges ]
|
||||||
|
|
||||||
# Génération de la conf de chaque prise
|
# Génération de la conf de chaque prise
|
||||||
for prise in range(1,nb_prises+1):
|
for prise in range(1,nb_prises+1):
|
||||||
self.aff.cycle()
|
self.aff.cycle()
|
||||||
|
|
||||||
# Conf par défaut : activée, autonégociation
|
# Conf par défaut : activée, autonégociation
|
||||||
prise_params = { 'prise' : prise , 'speed' : '',
|
prise_params = { 'prise' : prise , 'speed' : '',
|
||||||
'etat' : '' }
|
'etat' : '' }
|
||||||
annu_prise = '%i%02i' % (sw_num, prise) # prise telle que notée dans l'annuaire
|
annu_prise = '%i%02i' % (sw_num, prise) # prise telle que notée dans l'annuaire
|
||||||
|
|
||||||
if uplink_prises[bat].has_key(int(annu_prise)) :
|
if uplink_prises[bat].has_key(int(annu_prise)) :
|
||||||
### Prise d'uplink
|
### Prise d'uplink
|
||||||
prise_params['nom'] = uplink_prises[bat][int(annu_prise)]
|
prise_params['nom'] = uplink_prises[bat][int(annu_prise)]
|
||||||
|
@ -310,11 +319,12 @@ exit
|
||||||
vlans['adm_tagged'].append(prise)
|
vlans['adm_tagged'].append(prise)
|
||||||
vlans['wifi_tagged'].append(prise)
|
vlans['wifi_tagged'].append(prise)
|
||||||
vlans['hotspot_tagged'].append(prise)
|
vlans['hotspot_tagged'].append(prise)
|
||||||
|
vlans['appts_tagged'].append(prise)
|
||||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||||
continue
|
continue
|
||||||
|
|
||||||
params['non_uplinks'].append(prise)
|
params['non_uplinks'].append(prise)
|
||||||
|
|
||||||
if crans_prises.has_key("%s%s" % (bat.upper(), annu_prise)) :
|
if crans_prises.has_key("%s%s" % (bat.upper(), annu_prise)) :
|
||||||
### Prise réservée à l'association
|
### Prise réservée à l'association
|
||||||
wifi=0
|
wifi=0
|
||||||
|
@ -372,6 +382,7 @@ aaa port-access mac-based %(prise)s logoff-period 3600
|
||||||
aaa port-access mac-based %(prise)s unauth-vid 1
|
aaa port-access mac-based %(prise)s unauth-vid 1
|
||||||
""" % { 'nbmac': 1+2*len(chbres), 'prise': prise }
|
""" % { 'nbmac': 1+2*len(chbres), 'prise': prise }
|
||||||
|
|
||||||
|
|
||||||
# On donne à la prise un nom qui dépend des chambres
|
# On donne à la prise un nom qui dépend des chambres
|
||||||
# connectés dessus
|
# connectés dessus
|
||||||
if chbres :
|
if chbres :
|
||||||
|
@ -382,14 +393,22 @@ aaa port-access mac-based %(prise)s unauth-vid 1
|
||||||
else :
|
else :
|
||||||
prise_params['nom'] = 'Inconnu'
|
prise_params['nom'] = 'Inconnu'
|
||||||
|
|
||||||
|
# Si c'est une chambre d'un personnel de l'ENS, on lui donne
|
||||||
|
# le VLAN 21 en untagged
|
||||||
|
if chbres:
|
||||||
|
if chbres[0] in prises_appartements: # il faudrait faire
|
||||||
|
# un truc moins sale
|
||||||
|
vlans['appts_untagged'].append(prise)
|
||||||
|
prise_params['nom'] += "(appartement ENS)"
|
||||||
|
|
||||||
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
params['INTERFACES_CONF'] += self.interface_template % prise_params
|
||||||
|
|
||||||
# Petite verif
|
# Petite verif
|
||||||
if not params['uplinks'] or not params['non_uplinks'] :
|
if not params['uplinks'] or not params['non_uplinks'] :
|
||||||
raise RuntimeError('Switch sans uplink ou sans prise adhérent.')
|
raise RuntimeError('Switch sans uplink ou sans prise adhérent.')
|
||||||
|
|
||||||
def mk_list(liste_prise) :
|
def mk_list(liste_prise) :
|
||||||
"""
|
"""
|
||||||
transforme une liste de prises en une chaine pour le switch
|
transforme une liste de prises en une chaine pour le switch
|
||||||
exemple : 1, 3, 4, 5, 6, 7, 9, 10, 11, 12 => 1,3-7,9-12
|
exemple : 1, 3, 4, 5, 6, 7, 9, 10, 11, 12 => 1,3-7,9-12
|
||||||
"""
|
"""
|
||||||
|
@ -400,9 +419,9 @@ aaa port-access mac-based %(prise)s unauth-vid 1
|
||||||
i = liste_prise.pop(0)
|
i = liste_prise.pop(0)
|
||||||
groupe = [ i, i ]
|
groupe = [ i, i ]
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
liste_prise.append(9999) # apparaitra jamais dans la liste
|
liste_prise.append(9999) # apparaitra jamais dans la liste
|
||||||
|
|
||||||
while liste_prise :
|
while liste_prise :
|
||||||
nouveau = liste_prise.pop(0)
|
nouveau = liste_prise.pop(0)
|
||||||
if nouveau == groupe[1] + 1 :
|
if nouveau == groupe[1] + 1 :
|
||||||
|
@ -415,20 +434,20 @@ aaa port-access mac-based %(prise)s unauth-vid 1
|
||||||
result.append('-'.join(map(str,groupe)))
|
result.append('-'.join(map(str,groupe)))
|
||||||
# Réinit de groupe
|
# Réinit de groupe
|
||||||
groupe = [ nouveau, nouveau ]
|
groupe = [ nouveau, nouveau ]
|
||||||
|
|
||||||
return ','.join(result)
|
return ','.join(result)
|
||||||
|
|
||||||
# Saut de ligne parasite
|
# Saut de ligne parasite
|
||||||
params['INTERFACES_CONF'] = params['INTERFACES_CONF'][:-1].encode('iso-8859-15')
|
params['INTERFACES_CONF'] = params['INTERFACES_CONF'][:-1].encode('iso-8859-15')
|
||||||
|
|
||||||
# Conversion des listes
|
# Conversion des listes
|
||||||
for key in [ 'uplinks', 'non_uplinks' ] :
|
for key in [ 'uplinks', 'non_uplinks' ] :
|
||||||
params[key] = mk_list(params[key])
|
params[key] = mk_list(params[key])
|
||||||
for key, prises in vlans.items() :
|
for key, prises in vlans.items() :
|
||||||
vlans[key]=mk_list(prises)
|
vlans[key]=mk_list(prises)
|
||||||
|
|
||||||
# Config des vlans spéciaux (adm et wifi)
|
# Config des vlans spéciaux (adm, wifi et appartements)
|
||||||
for v in ('adm', 'wifi', 'hotspot') :
|
for v in ('adm', 'wifi', 'hotspot', 'appts') :
|
||||||
params['prises_%s' % v] = ''
|
params['prises_%s' % v] = ''
|
||||||
for t in ('tagged' , 'untagged') :
|
for t in ('tagged' , 'untagged') :
|
||||||
if vlans['%s_%s' % (v,t)] :
|
if vlans['%s_%s' % (v,t)] :
|
||||||
|
@ -445,13 +464,13 @@ aaa port-access mac-based %(prise)s unauth-vid 1
|
||||||
fd = self._open_conf(self.CONF_REP + switch + '.conf')
|
fd = self._open_conf(self.CONF_REP + switch + '.conf')
|
||||||
fd.write(self.config % params)
|
fd.write(self.config % params)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
if __name__ == '__main__' :
|
if __name__ == '__main__' :
|
||||||
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) == 1 :
|
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 <switch>" % sys.argv[0].split('/')[-1].split('.')[0]
|
||||||
print "Génération du fichier de configuration des switchs donnés."
|
print "Génération du fichier de configuration des switchs donnés."
|
||||||
sys.exit(255)
|
sys.exit(255)
|
||||||
|
|
||||||
if sys.argv[1] == 'all' :
|
if sys.argv[1] == 'all' :
|
||||||
switchs = tuple(all_switchs())
|
switchs = tuple(all_switchs())
|
||||||
else :
|
else :
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue