pahekoldap
This commit is contained in:
@@ -4,6 +4,7 @@ import sys
|
|||||||
|
|
||||||
from lib.paheko import Paheko
|
from lib.paheko import Paheko
|
||||||
from lib.ldap import Ldap
|
from lib.ldap import Ldap
|
||||||
|
from lib.ssh import Ssh
|
||||||
|
|
||||||
paheko = Paheko()
|
paheko = Paheko()
|
||||||
categorie_membres = paheko.get_categorie_id("Membres")
|
categorie_membres = paheko.get_categorie_id("Membres")
|
||||||
@@ -78,6 +79,18 @@ def test_mails_orga(paheko_entry):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
def test_server_location(paheko_entry):
|
||||||
|
# Vérifie que le serveur est bien renseigné.
|
||||||
|
is_orga = paheko_entry["admin_orga"].strip("'") == "Oui"
|
||||||
|
if is_orga:
|
||||||
|
serveur_prod = paheko_entry["serveur_prod"]
|
||||||
|
if not serveur_prod:
|
||||||
|
return False
|
||||||
|
directory = f"/kaz/dockers/{paheko_entry['nom_orga']}-orga"
|
||||||
|
with Ssh(serveur_prod) as ssh:
|
||||||
|
return ssh.check_return_code(f"ls {directory}") == 0
|
||||||
|
return True
|
||||||
|
|
||||||
with Ldap() as ldap:
|
with Ldap() as ldap:
|
||||||
try:
|
try:
|
||||||
not_in_ldap = []
|
not_in_ldap = []
|
||||||
@@ -86,6 +99,7 @@ with Ldap() as ldap:
|
|||||||
quota = []
|
quota = []
|
||||||
services = []
|
services = []
|
||||||
mails_orgas = []
|
mails_orgas = []
|
||||||
|
servers_locations = []
|
||||||
for membre in membres:
|
for membre in membres:
|
||||||
ldap_entry = ldap.get_email(membre["email"])
|
ldap_entry = ldap.get_email(membre["email"])
|
||||||
if ldap_entry:
|
if ldap_entry:
|
||||||
@@ -108,6 +122,9 @@ with Ldap() as ldap:
|
|||||||
suffix = '\n '.join(mails_orga)
|
suffix = '\n '.join(mails_orga)
|
||||||
mails_orgas.append(f"{membre['email']}:\n {suffix}")
|
mails_orgas.append(f"{membre['email']}:\n {suffix}")
|
||||||
|
|
||||||
|
if not test_server_location(membre):
|
||||||
|
servers_locations.append(f"{membre['email']}, pas trouvé sur {membre['serveur_prod']}")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
not_in_ldap.append(f"{membre['email']} / id : {membre['id']}")
|
not_in_ldap.append(f"{membre['email']} / id : {membre['id']}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -129,10 +146,9 @@ with Ldap() as ldap:
|
|||||||
print("Mails dans paheko mais pas dans le LDAP :")
|
print("Mails dans paheko mais pas dans le LDAP :")
|
||||||
print("\n".join(not_in_ldap))
|
print("\n".join(not_in_ldap))
|
||||||
|
|
||||||
print("Mails dans lda LDAP mais pas dans paheko :")
|
print("Mails dans le LDAP mais pas dans paheko :")
|
||||||
print("\n".join(not_in_paheko))
|
print("\n".join(not_in_paheko))
|
||||||
|
|
||||||
|
|
||||||
print("\nMails de secours pas ok dans le LDAP :")
|
print("\nMails de secours pas ok dans le LDAP :")
|
||||||
print("\n".join(mail_secours))
|
print("\n".join(mail_secours))
|
||||||
|
|
||||||
@@ -145,3 +161,5 @@ print("\n".join(quota))
|
|||||||
print("\nMails d'orga dans paheko mais manquant dans le LDAP :")
|
print("\nMails d'orga dans paheko mais manquant dans le LDAP :")
|
||||||
print("\n".join(mails_orgas))
|
print("\n".join(mails_orgas))
|
||||||
|
|
||||||
|
print("\nOrgas pas trouvées sur le serveur renseigné dans paheko :")
|
||||||
|
print("\n".join(servers_locations))
|
24
bin/lib/ssh.py
Normal file
24
bin/lib/ssh.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import paramiko
|
||||||
|
|
||||||
|
class Ssh:
|
||||||
|
def __init__(self, server, username="root"):
|
||||||
|
self.ssh_connection = None
|
||||||
|
self.server = server
|
||||||
|
self.username = username
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.ssh_connection = paramiko.SSHClient()
|
||||||
|
self.ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
self.ssh_connection.connect(self.server, port=2201, username=self.username)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, tp, e, traceback):
|
||||||
|
self.ssh_connection.close()
|
||||||
|
|
||||||
|
def check_output(self, command):
|
||||||
|
ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_connection.exec_command(command)
|
||||||
|
return ssh_stdout.read().decode()
|
||||||
|
|
||||||
|
def check_return_code(self, command):
|
||||||
|
ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_connection.exec_command(command)
|
||||||
|
return ssh_stdout.channel.recv_exit_status()
|
Reference in New Issue
Block a user