1
|
|
2
|
|
3
|
|
4
|
import xmlrpclib, getpass, sys, os, glob, time, shutil
|
5
|
|
6
|
|
7
|
|
8
|
LOG_FILE = '/root/rapport_purge_dico.txt'
|
9
|
BACKUP_DIR = '/root/backup_purge_dicts'
|
10
|
|
11
|
def log(msg, term=True):
|
12
|
if os.path.isfile(LOG_FILE):
|
13
|
f_rapport = open(LOG_FILE, 'a')
|
14
|
else:
|
15
|
f_rapport = open(LOG_FILE, 'w')
|
16
|
if term:
|
17
|
print("{0}".format(msg.encode('utf-8')))
|
18
|
f_rapport.write("{0}\n".format(msg.encode('utf-8')))
|
19
|
f_rapport.close()
|
20
|
|
21
|
def purge_dict(id_serv, dict_path):
|
22
|
if not os.path.isdir(os.path.join(BACKUP_DIR, str(id_serv))):
|
23
|
os.makedirs(os.path.join(BACKUP_DIR, str(id_serv)))
|
24
|
shutil.move(dict_path, os.path.join(BACKUP_DIR, str(id_serv), os.path.basename(dict_path)))
|
25
|
|
26
|
def check_serveurs(z_proxy, maj_client=False, envoi_conf=False):
|
27
|
rc, info_modules = z_proxy.modules.get_module()
|
28
|
for mod in info_modules:
|
29
|
if mod['version'] == 5:
|
30
|
old_client = []
|
31
|
bad_client = []
|
32
|
purged = []
|
33
|
conf_client = []
|
34
|
log(u"\n* {0} *".format(mod['libelle']))
|
35
|
rc, groupe_serv = z_proxy.serveurs.groupe_serveur({'module_actuel':mod['id']})
|
36
|
for serv in groupe_serv:
|
37
|
id_serv = serv['id']
|
38
|
rne_serv = serv['rne']
|
39
|
rc, client_ok = z_proxy.serveurs.check_min_version(id_serv, 'zephir-client', '2.3-eole59')
|
40
|
if rc == 0 or client_ok == False:
|
41
|
old_client.append(str(id_serv))
|
42
|
|
43
|
rc, client_nok = z_proxy.serveurs.check_min_version(id_serv, 'zephir-client', '2.3-eole58')
|
44
|
if rc == 0 or client_nok == True:
|
45
|
|
46
|
if maj_client:
|
47
|
|
48
|
rc, purge_ok = z_proxy.uucp.purge_actions([id_serv])
|
49
|
rc, maj_ok = z_proxy.uucp.maj_client(id_serv)
|
50
|
if rc == 0:
|
51
|
log(u" ! Erreur recontrée lors de la mise à jour du client pour le serveur {0}: {1}".format(id_serv, maj_ok))
|
52
|
|
53
|
path_dicos = os.path.join('/var/lib/zephir/conf', rne_serv, str(id_serv), 'dicos')
|
54
|
for local_dict in glob.glob(os.path.join(path_dicos, 'local', '*.xml')):
|
55
|
if os.path.exists(os.path.join(path_dicos, 'module', os.path.basename(local_dict))):
|
56
|
|
57
|
purge_dict(id_serv, local_dict)
|
58
|
purged.append(str(id_serv))
|
59
|
|
60
|
if client_ok and envoi_conf:
|
61
|
conf_client.append(str(id_serv))
|
62
|
rc, conf_ok = z_proxy.uucp.configure(id_serv, restart=1, content=2)
|
63
|
if rc == 0:
|
64
|
log(u" ! Erreur recontrée lors de la mise à jour du client pour le serveur {0}: {1}".format(id_serv, conf_ok))
|
65
|
if old_client:
|
66
|
log(u" Serveurs n'ayant pas le dernier client (ou version non remontée): {0}".format(",".join(old_client)))
|
67
|
if purged:
|
68
|
log(u" Dictionnaires purgés sur les serveurs : {0}".format(",".join(purged)))
|
69
|
log(u" - Les dictionnaires purgés sont conservés dans le répertoire {0}".format(BACKUP_DIR))
|
70
|
if conf_client:
|
71
|
log(u" Envoi de configuration + reconfigure sur les serveurs : {0}".format(",".join(conf_client)))
|
72
|
print "\n\nUn rapport a été généré: {0}".format(LOG_FILE)
|
73
|
|
74
|
|
75
|
if __name__ == '__main__':
|
76
|
|
77
|
|
78
|
|
79
|
|
80
|
user = raw_input("nom de l'utilisateur zephir :")
|
81
|
pwd = getpass.getpass("mot de passe :")
|
82
|
|
83
|
|
84
|
print "\nSeulement si vous avez importé le paquet 'zephir-client_2.3-eole59' dans l'interface d'administration de zephir"
|
85
|
resp = raw_input("Demander un mise à jour du client pour les serveurs ayant la version posant problème (O/N) ? [N] :")
|
86
|
maj_client = resp.upper() in ('O', 'OUI')
|
87
|
resp = raw_input("\nDemander un envoi de configuration (dicos/templates/patch + reconfigure) après vérification (O/N) ? [N] :")
|
88
|
envoi_conf = resp.upper() in ('O', 'OUI')
|
89
|
zephir_proxy = xmlrpclib.ServerProxy('http://%s:%s@127.0.0.1:7081' % (user, pwd))
|
90
|
try:
|
91
|
|
92
|
log(u"\n\n{0}: -- Vérification des dictionnaires en erreur\n".format(time.ctime()))
|
93
|
log(u" Mise à jour du client : {0}".format(maj_client), False)
|
94
|
log(u" Envoi de configuration : {0}".format(envoi_conf), False)
|
95
|
check_serveurs(zephir_proxy, maj_client, envoi_conf)
|
96
|
except xmlrpclib.ProtocolError, err:
|
97
|
print "erreur, autorisations insuffisantes"
|
98
|
except Exception, err:
|
99
|
print "erreur rencontrée :"
|
100
|
print err
|