import ldap import ldap.sasl import ldap.modlist import xmlrpclib import os import json class Matrix: def __init__(self): self.first_run = True #def __init__ def n4d_cron(self,minute): if self.first_run or ( minute % 60 == 0 ) : if self.first_run: self.first_run = False self.update_from_matrix() #def n4d_cron def update_from_matrix(self): try: if not objects['SlapdManager'].test_ldap_connection(): if not objects['SlapdManager'].connection_ldap(): return {"status":False,"msg":"Connection with ldap is not create"} except: return 'Not initialized' aux_file = open('/etc/matrix_config','r') matrix_options = json.load(aux_file) c = xmlrpclib.ServerProxy("https://" + matrix_options['server_ip'] + ":9779") try: list_changes = c.get_users('','Matrix') except: return "Server is down" if list_changes[0][0] == 'ou=llxadmin,dc=ma5,dc=lliurex,dc=net': objects['SlapdManager'].recursive_delete(list_changes[0][0]) for x in list_changes: aux_dic = {} aux_dic[x[0]]= x[1] objects['SlapdManager'].insert_dictionary(aux_dic) return "Ok" #return list_changes[0] if __name__ == '__main__': a = Matrix() a.update_from_matrix()