Gestion des bornes.
Meilleure gestion des erreurs. Fichier commun zamok et nectaris darcs-hash:20040906094417-d1718-e36642e0349b2d0a24c29021eea0b54d239cf20e.gz
This commit is contained in:
parent
a60988c663
commit
a5abd19754
1 changed files with 162 additions and 127 deletions
|
@ -24,7 +24,7 @@ make_lock('auto_generate')
|
||||||
##### Options fournies ?
|
##### Options fournies ?
|
||||||
try :
|
try :
|
||||||
if len(sys.argv) > 1 :
|
if len(sys.argv) > 1 :
|
||||||
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall' ])
|
options, arg = getopt.getopt(sys.argv[1:], '', ['quiet', 'home=', 'mail_bienvenue=', 'ML-ENS=', 'droits', 'switch=' , 'dhcp', 'dns', 'firewall', 'conf_wifi', 'bornes_wifi=' ])
|
||||||
else :
|
else :
|
||||||
options, arg = ( [],'')
|
options, arg = ( [],'')
|
||||||
except getopt.error, msg :
|
except getopt.error, msg :
|
||||||
|
@ -49,138 +49,173 @@ else :
|
||||||
auto = 0
|
auto = 0
|
||||||
if debug : print 'Services à redémarrer imposés (non lecture de la base LDAP)'
|
if debug : print 'Services à redémarrer imposés (non lecture de la base LDAP)'
|
||||||
|
|
||||||
inst = []
|
from socket import gethostname
|
||||||
if 'home' in to_do.keys() :
|
|
||||||
cprint('Création home','gras')
|
|
||||||
for args in to_do['home'] :
|
|
||||||
anim('\t' + args)
|
|
||||||
try :
|
|
||||||
home, uid, login = args.split(',')
|
|
||||||
os.mkdir(home, 0755)
|
|
||||||
os.chown(home, int(uid) ,config.gid)
|
|
||||||
os.mkdir(home + '/Mail', 0700)
|
|
||||||
os.chown(home + '/Mail', int(uid) ,config.gid)
|
|
||||||
status, output = commands.getstatusoutput('/usr/sbin/edquota -p pauget %s' % login )
|
|
||||||
if status :
|
|
||||||
print WARNING
|
|
||||||
if debug :
|
|
||||||
sys.stderr.write(output+'\n')
|
|
||||||
else :
|
|
||||||
print OK
|
|
||||||
if auto : db.services_to_restart('-home')
|
|
||||||
except :
|
|
||||||
print ERREUR
|
|
||||||
if debug :
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
if 'mail_bienvenue' in to_do.keys() :
|
|
||||||
if auto : db.services_to_restart('-mail_bienvenue')
|
|
||||||
cprint('Envoi mail de bienvenue','gras')
|
|
||||||
pas_fait = []
|
|
||||||
for mail in to_do['mail_bienvenue'] :
|
|
||||||
anim('\t' + mail)
|
|
||||||
try :
|
|
||||||
From = "respbats@crans.org"
|
|
||||||
To = mail
|
|
||||||
if To.find('@') == -1 : To += '@crans.org'
|
|
||||||
conn=smtplib.SMTP(smtpserv)
|
|
||||||
conn.sendmail(From, To , config.txt_mail_bienvenue % { 'From' : From, 'To' : To })
|
|
||||||
conn.quit()
|
|
||||||
print OK
|
|
||||||
except Exception, c:
|
|
||||||
print ERREUR
|
|
||||||
pas_fait.append(mail)
|
|
||||||
if debug :
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
if auto and pas_fait :
|
|
||||||
db.services_to_restart('mail_bienvenue',pas_fait)
|
|
||||||
|
|
||||||
if 'ML-ENS' in to_do.keys() :
|
|
||||||
cprint('Inscription ML-ENS','gras')
|
|
||||||
for mail in to_do['ML-ENS'] :
|
|
||||||
anim('\t'+mail)
|
|
||||||
status, output = commands.getstatusoutput("echo '%s' | /usr/sbin/add_members -r - com-ens >/dev/null 2>&1" % mail)
|
|
||||||
if status :
|
|
||||||
# Il y a eu une erreur
|
|
||||||
print ERREUR
|
|
||||||
if debug :
|
|
||||||
sys.stderr.write(output+'\n')
|
|
||||||
else :
|
|
||||||
print OK
|
|
||||||
db.services_to_restart('-ML-ENS')
|
|
||||||
|
|
||||||
if 'droits' in to_do.keys() :
|
|
||||||
from gen_confs.droits import droits
|
|
||||||
a = droits()
|
|
||||||
a.debug = debug
|
|
||||||
a.reconfigure()
|
|
||||||
db.services_to_restart('-droits')
|
|
||||||
|
|
||||||
if 'switch' in to_do.keys() :
|
if gethostname().split(".")[0] == 'zamok':
|
||||||
from gen_confs.switchs import switch
|
inst = []
|
||||||
a = switch(to_do['switch'])
|
if 'home' in to_do.keys() :
|
||||||
a.debug = debug
|
if auto : db.services_to_restart('-home')
|
||||||
a.reconfigure()
|
cprint('Création home','gras')
|
||||||
if auto : db.services_to_restart('-switch')
|
for args in to_do['home'] :
|
||||||
|
anim('\t' + args)
|
||||||
# Les services suivants ont besoin de la liste des machines
|
try :
|
||||||
# On va donc la lire une seule fois pour leur passer ensuite
|
home, uid, login = args.split(',')
|
||||||
|
os.mkdir(home, 0755)
|
||||||
|
os.chown(home, int(uid) ,config.gid)
|
||||||
|
os.mkdir(home + '/Mail', 0700)
|
||||||
|
os.chown(home + '/Mail', int(uid) ,config.gid)
|
||||||
|
status, output = commands.getstatusoutput('/usr/sbin/edquota -p pauget %s' % login )
|
||||||
|
if status :
|
||||||
|
print WARNING
|
||||||
|
if debug :
|
||||||
|
sys.stderr.write(output+'\n')
|
||||||
|
else :
|
||||||
|
print OK
|
||||||
|
except :
|
||||||
|
print ERREUR
|
||||||
|
# On devra le refaire la prochaine fois
|
||||||
|
if auto : db.services_to_restart('home',[args])
|
||||||
|
if debug :
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
if 'mail_bienvenue' in to_do.keys() :
|
||||||
|
if auto : db.services_to_restart('-mail_bienvenue')
|
||||||
|
cprint('Envoi mail de bienvenue','gras')
|
||||||
|
pas_fait = []
|
||||||
|
for mail in to_do['mail_bienvenue'] :
|
||||||
|
anim('\t' + mail)
|
||||||
|
try :
|
||||||
|
From = "respbats@crans.org"
|
||||||
|
To = mail
|
||||||
|
if To.find('@') == -1 : To += '@crans.org'
|
||||||
|
conn=smtplib.SMTP(smtpserv)
|
||||||
|
conn.sendmail(From, To , config.txt_mail_bienvenue % { 'From' : From, 'To' : To })
|
||||||
|
conn.quit()
|
||||||
|
print OK
|
||||||
|
except Exception, c:
|
||||||
|
print ERREUR
|
||||||
|
pas_fait.append(mail)
|
||||||
|
if debug :
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
if auto and pas_fait :
|
||||||
|
db.services_to_restart('mail_bienvenue',pas_fait)
|
||||||
|
|
||||||
restartlater = []
|
if 'ML-ENS' in to_do.keys() :
|
||||||
if 'firewall' in to_do.keys() :
|
if auto : db.services_to_restart('-ML-ENS')
|
||||||
# Quand sila et komaz liront la base LDAP
|
cprint('Inscription ML-ENS','gras')
|
||||||
# db.services_to_restart('firewall-komaz')
|
for mail in to_do['ML-ENS'] :
|
||||||
# db.services_to_restart('firewall-sila')
|
anim('\t'+mail)
|
||||||
from gen_confs.firewall import firewall
|
status, output = commands.getstatusoutput("echo '%s' | /usr/sbin/add_members -r - com-ens >/dev/null 2>&1" % mail)
|
||||||
inst.append([firewall(),"firewall"])
|
if status :
|
||||||
|
# Il y a eu une erreur
|
||||||
if 'dns' in to_do.keys() :
|
print ERREUR
|
||||||
from gen_confs.bind import dns
|
if auto : db.services_to_restart('ML-ENS', [mail])
|
||||||
inst.append([dns(),"dns"])
|
if debug :
|
||||||
|
sys.stderr.write(output+'\n')
|
||||||
if 'dhcp' in to_do.keys() :
|
else :
|
||||||
from gen_confs.dhcpd import dhcp
|
print OK
|
||||||
inst.append([dhcp(),"dhcp"])
|
|
||||||
|
|
||||||
# On indique que les services seront a priori redemarrés
|
if 'droits' in to_do.keys() :
|
||||||
if auto :
|
if auto : db.services_to_restart('-droits')
|
||||||
for i in inst:
|
try:
|
||||||
db.services_to_restart("-%s" % i[1])
|
from gen_confs.droits import droits
|
||||||
|
a = droits()
|
||||||
|
a.debug = debug
|
||||||
|
a.reconfigure()
|
||||||
|
except:
|
||||||
|
if auto : db.services_to_restart('droits')
|
||||||
|
raise
|
||||||
|
|
||||||
##### On fait ce qu'il reste à faire
|
if 'switch' in to_do.keys() :
|
||||||
|
if auto : db.services_to_restart('-switch')
|
||||||
|
try:
|
||||||
|
from gen_confs.switchs import switch
|
||||||
|
a = switch(to_do['switch'])
|
||||||
|
a.debug = debug
|
||||||
|
a.reconfigure()
|
||||||
|
except:
|
||||||
|
if auto : db.services_to_restart('switch',to_do['switch'])
|
||||||
|
raise
|
||||||
|
|
||||||
if inst :
|
# Les services suivants ont besoin de la liste des machines
|
||||||
##### Récolte des données
|
# On va donc la lire une seule fois pour leur passer ensuite
|
||||||
cprint('Lecture base LDAP','gras')
|
|
||||||
# Machines de l'assoce
|
|
||||||
machines = crans(db.conn).machines()
|
|
||||||
# Machines des adhérents et clubs de l'année en cours
|
|
||||||
base = db.search('paiement=%s' % ann_scol)
|
|
||||||
base = base['adherent'] + base['club']
|
|
||||||
a = anim('\ttri machines',len(base))
|
|
||||||
for adh in base :
|
|
||||||
a.cycle()
|
|
||||||
# Adhérent ayant payé l'année en cours
|
|
||||||
if 'bloq' in adh.blacklist_actif() :
|
|
||||||
# Adhérent ignoré
|
|
||||||
continue
|
|
||||||
machines += adh.machines()
|
|
||||||
a.reinit()
|
|
||||||
print OK
|
|
||||||
|
|
||||||
#### Reconfiguration des services
|
restartlater = []
|
||||||
|
if 'firewall' in to_do.keys() :
|
||||||
for i in inst :
|
# Quand sila et komaz liront la base LDAP
|
||||||
i[0].debug = debug
|
# db.services_to_restart('firewall-komaz')
|
||||||
i[0].machines = machines
|
# db.services_to_restart('firewall-sila')
|
||||||
try :
|
from gen_confs.firewall import firewall
|
||||||
i[0].reconfigure()
|
inst.append([firewall(),"firewall"])
|
||||||
except :
|
|
||||||
# Erreur, il faudra relancer le service la prochaine fois
|
if 'dns' in to_do.keys() :
|
||||||
if auto : db.services_to_restart('%s' % i[1])
|
from gen_confs.bind import dns
|
||||||
sys.stderr.write('Erreur dans le service %s\n' % i[1])
|
inst.append([dns(),"dns"])
|
||||||
|
|
||||||
|
if 'dhcp' in to_do.keys() :
|
||||||
|
from gen_confs.dhcpd import dhcp
|
||||||
|
inst.append([dhcp(),"dhcp"])
|
||||||
|
|
||||||
|
# On indique que les services seront a priori redemarrés
|
||||||
|
if auto :
|
||||||
|
for i in inst:
|
||||||
|
db.services_to_restart("-%s" % i[1])
|
||||||
|
## On fait ce qu'il reste à faire
|
||||||
|
|
||||||
|
if inst :
|
||||||
|
# Récolte des données
|
||||||
|
cprint('Lecture base LDAP','gras')
|
||||||
|
# Machines de l'assoce
|
||||||
|
machines = crans(db.conn).machines()
|
||||||
|
# Machines des adhérents et clubs de l'année en cours
|
||||||
|
base = db.search('paiement=%s' % ann_scol)
|
||||||
|
base = base['adherent'] + base['club']
|
||||||
|
a = anim('\ttri machines',len(base))
|
||||||
|
for adh in base :
|
||||||
|
a.cycle()
|
||||||
|
# Adhérent ayant payé l'année en cours
|
||||||
|
if 'bloq' in adh.blacklist_actif() :
|
||||||
|
# Adhérent ignoré
|
||||||
|
continue
|
||||||
|
machines += adh.machines()
|
||||||
|
a.reinit()
|
||||||
|
print OK
|
||||||
|
|
||||||
|
# Reconfiguration des services
|
||||||
|
|
||||||
|
for i in inst :
|
||||||
|
i[0].debug = debug
|
||||||
|
i[0].machines = machines
|
||||||
|
try :
|
||||||
|
i[0].reconfigure()
|
||||||
|
except :
|
||||||
|
# Erreur, il faudra relancer le service la prochaine fois
|
||||||
|
if auto : db.services_to_restart('%s' % i[1])
|
||||||
|
sys.stderr.write('Erreur dans le service %s\n' % i[1])
|
||||||
|
elif gethostname().split(".")[0] == 'nectaris':
|
||||||
|
# On s'occupe de nectaris
|
||||||
|
if 'conf_wifi' in to_do.keys():
|
||||||
|
if auto : db.services_to_restart('-conf_wifi')
|
||||||
|
try:
|
||||||
|
from gen_confs.wifi import wifi
|
||||||
|
a = wifi()
|
||||||
|
a.debug = debug
|
||||||
|
a.reconfigure()
|
||||||
|
except:
|
||||||
|
if auto : db.services_to_restart('conf_wifi')
|
||||||
|
raise
|
||||||
|
if 'bornes_wifi' in to_do.keys():
|
||||||
|
if auto : db.services_to_restart('-bornes_wifi')
|
||||||
|
try:
|
||||||
|
from gen_confs.wifi import bornes_wifi
|
||||||
|
a = bornes_wifi(to_do['bornes_wifi'])
|
||||||
|
a.debug = debug
|
||||||
|
a.reconfigure()
|
||||||
|
except:
|
||||||
|
# Pas terrible : on va redemarrer les bornes qui ont redemarré correctement
|
||||||
|
if auto : db.services_to_restart('bornes_wifi', to_do['bornes_wifi'])
|
||||||
|
raise
|
||||||
|
|
||||||
if debug :
|
if debug :
|
||||||
print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart()
|
print 'Non traité ici mais signalé dans la base LDAP : \n\t', db.services_to_restart()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue