[services] Redémarrage des services object lors de la creation ou suppression d'un objet
À contrario des services attributs dépendant qui eux marchait déjà très bien, je pense donc à del_user, home, et mail_bienvenue
This commit is contained in:
parent
10f9ce666d
commit
2a6f5d6a9a
2 changed files with 36 additions and 14 deletions
|
@ -52,7 +52,6 @@ import lc_ldap
|
||||||
import crans_utils
|
import crans_utils
|
||||||
import attributs
|
import attributs
|
||||||
import ldap_locks
|
import ldap_locks
|
||||||
import services
|
|
||||||
import variables
|
import variables
|
||||||
|
|
||||||
## import de /usr/scripts/
|
## import de /usr/scripts/
|
||||||
|
@ -238,7 +237,7 @@ class CransLdapObject(object):
|
||||||
self.conn.lockholder.purge(id(self))
|
self.conn.lockholder.purge(id(self))
|
||||||
|
|
||||||
# Services à relancer
|
# Services à relancer
|
||||||
services.services_to_restart(self.conn, {}, self._modifs)
|
services.services_to_restart(self.conn, {}, self._modifs, created_object=[self])
|
||||||
self._post_creation()
|
self._post_creation()
|
||||||
|
|
||||||
# Vérifications après insertion.
|
# Vérifications après insertion.
|
||||||
|
@ -271,7 +270,7 @@ class CransLdapObject(object):
|
||||||
self.conn.delete_s(self.dn)
|
self.conn.delete_s(self.dn)
|
||||||
self.conn.lockholder.purge(id(self))
|
self.conn.lockholder.purge(id(self))
|
||||||
self._post_deletion()
|
self._post_deletion()
|
||||||
services.services_to_restart(self.conn, self.attrs, {})
|
services.services_to_restart(self.conn, self.attrs, {}, deleted_object=[self])
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Sauvegarde dans la base les modifications apportées à l'objet.
|
"""Sauvegarde dans la base les modifications apportées à l'objet.
|
||||||
|
@ -619,7 +618,7 @@ class proprio(CransLdapObject):
|
||||||
machine.delete(comm, login)
|
machine.delete(comm, login)
|
||||||
self.bury(comm, login)
|
self.bury(comm, login)
|
||||||
self.conn.delete_s(self.dn)
|
self.conn.delete_s(self.dn)
|
||||||
services.services_to_restart(self.conn, self.attrs, {})
|
services.services_to_restart(self.conn, self.attrs, {}, deleted_object=[self])
|
||||||
|
|
||||||
class machine(CransLdapObject):
|
class machine(CransLdapObject):
|
||||||
u""" Une machine """
|
u""" Une machine """
|
||||||
|
@ -945,3 +944,5 @@ class facture(CransLdapObject):
|
||||||
class service(CransLdapObject):
|
class service(CransLdapObject):
|
||||||
ldap_name = "service"
|
ldap_name = "service"
|
||||||
|
|
||||||
|
|
||||||
|
import services
|
||||||
|
|
41
services.py
41
services.py
|
@ -23,12 +23,16 @@ services_to_attrs['ports'] = [ attributs.portUDPout, attributs.portUDPin, attrib
|
||||||
services_to_attrs['droits'] = [ attributs.droits ]
|
services_to_attrs['droits'] = [ attributs.droits ]
|
||||||
services_to_attrs['mail_ajout_droits'] = [ attributs.droits ]
|
services_to_attrs['mail_ajout_droits'] = [ attributs.droits ]
|
||||||
services_to_attrs['dhcp'] = services_to_attrs['macip']
|
services_to_attrs['dhcp'] = services_to_attrs['macip']
|
||||||
#services_to_attrs['home'] = [ attributs.homeDirectory ] ## Vérifier que ça ne fasse pas de caca
|
|
||||||
|
|
||||||
services_to_attrs['del_user'] = []
|
|
||||||
services_to_attrs['mail_bienvenue'] = []
|
|
||||||
services_to_attrs['mail_modif'] = []
|
services_to_attrs['mail_modif'] = []
|
||||||
|
|
||||||
|
services_to_objects={}
|
||||||
|
services_to_objects['delete']={}
|
||||||
|
services_to_objects['create']={}
|
||||||
|
services_to_objects['create']['home'] = [objets.adherent, objets.club]
|
||||||
|
services_to_objects['create']['mail_bienvenue'] = [objets.adherent]
|
||||||
|
services_to_objects['delete']['del_user'] = [objets.adherent, objets.club]
|
||||||
|
|
||||||
|
|
||||||
# génération des arguments du service à redémarrer (par defaut [])
|
# génération des arguments du service à redémarrer (par defaut [])
|
||||||
services_to_args={}
|
services_to_args={}
|
||||||
|
@ -39,15 +43,22 @@ services_to_args['port']=lambda x: [str(x)] if isinstance(x, attributs.ipHostNum
|
||||||
services_to_args['home']=lambda x: u'cransAccount' in [ str(o) for o in x.parent['objectClass']] and [ "%s,%s,%s" % (x.parent['homeDirectory'][0],x.parent['uidNumber'][0],x.parent['uid'][0]) ] or [ "%s,%s,%s,%s" % (x.parent['homeDirectory'][0],x.parent['uidNumber'][0],x.parent['uid'][0],x.parent['mail'][0]) ]
|
services_to_args['home']=lambda x: u'cransAccount' in [ str(o) for o in x.parent['objectClass']] and [ "%s,%s,%s" % (x.parent['homeDirectory'][0],x.parent['uidNumber'][0],x.parent['uid'][0]) ] or [ "%s,%s,%s,%s" % (x.parent['homeDirectory'][0],x.parent['uidNumber'][0],x.parent['uid'][0],x.parent['mail'][0]) ]
|
||||||
services_to_args['mail_ajout_droits'] = lambda x: "%s:%s" % (x.parent['uid'][0], x)
|
services_to_args['mail_ajout_droits'] = lambda x: "%s:%s" % (x.parent['uid'][0], x)
|
||||||
|
|
||||||
# Quand redémarrer le service (par defaut 0)
|
# Quand redémarrer le service (par defaut [0]), doit returner un iterable avec potentiellement plusieurs dates
|
||||||
services_to_time={}
|
services_to_time={}
|
||||||
services_to_time['blacklist']=lambda x: isinstance(x, attributs.blacklist) and (0 if x.value['debut'] == '-' else x.value['debut']) or 0
|
services_to_time['blacklist']=lambda x: isinstance(x, attributs.blacklist) and set([(0 if x.value['debut'] == '-' else x.value['debut']), (0 if x.value['fin'] == '-' else x.value['fin'])]) or [0]
|
||||||
|
|
||||||
attrs_to_services = {}
|
attrs_to_services = {}
|
||||||
for (key, values) in services_to_attrs.items():
|
for (key, values) in services_to_attrs.items():
|
||||||
for value in values:
|
for value in values:
|
||||||
attrs_to_services[value] = attrs_to_services.get(value, []) + [key]
|
attrs_to_services[value] = attrs_to_services.get(value, []) + [key]
|
||||||
|
|
||||||
|
objects_to_services={}
|
||||||
|
for status in ['delete', 'create']:
|
||||||
|
objects_to_services[status]={}
|
||||||
|
for (key, values) in services_to_objects[status].items():
|
||||||
|
for value in values:
|
||||||
|
objects_to_services[status][value]=objects_to_services[status].get(value, []) + [key]
|
||||||
|
|
||||||
# Identique à celle dans ldap_crans.py
|
# Identique à celle dans ldap_crans.py
|
||||||
def preattr(val):
|
def preattr(val):
|
||||||
"""
|
"""
|
||||||
|
@ -184,7 +195,7 @@ def service_to_restart(conn, new=None, args=[], start=0):
|
||||||
# Existe déja => rien à faire
|
# Existe déja => rien à faire
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def services_to_restart(conn, old_attrs={}, new_attrs={}):
|
def services_to_restart(conn, old_attrs={}, new_attrs={}, created_object=[], deleted_object=[]):
|
||||||
"""Détermine quels sont les services à reconfigurer"""
|
"""Détermine quels sont les services à reconfigurer"""
|
||||||
old_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in old_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value)
|
old_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in old_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value)
|
||||||
new_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in new_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value)
|
new_attrs_c = dict((attributs.AttributeFactory.get(key), value) for key,value in new_attrs.items() if attributs.AttributeFactory.get(key, fallback=None) != None and value)
|
||||||
|
@ -203,9 +214,16 @@ def services_to_restart(conn, old_attrs={}, new_attrs={}):
|
||||||
for service in attrs_to_services.get(attr.__class__, []):
|
for service in attrs_to_services.get(attr.__class__, []):
|
||||||
services_to_restart[service] = services_to_restart.get(service, []) + [attr]
|
services_to_restart[service] = services_to_restart.get(service, []) + [attr]
|
||||||
|
|
||||||
|
for obj in created_object:
|
||||||
|
for service in objects_to_services['create'].get(obj.__class__, []):
|
||||||
|
services_to_restart[service] = services_to_restart.get(service, [])
|
||||||
|
|
||||||
|
for obj in deleted_object:
|
||||||
|
for service in objects_to_services['delete'].get(obj.__class__, []):
|
||||||
|
services_to_restart[service] = services_to_restart.get(service, [])
|
||||||
|
|
||||||
for service in services_to_restart.keys():
|
for service in services_to_restart.keys():
|
||||||
for attr in services_to_restart[service]:
|
for attr in services_to_restart[service]:
|
||||||
start = 0
|
|
||||||
arg = set()
|
arg = set()
|
||||||
if service in services_to_args.keys():
|
if service in services_to_args.keys():
|
||||||
arg = arg.union(services_to_args[service](attr))
|
arg = arg.union(services_to_args[service](attr))
|
||||||
|
@ -232,9 +250,12 @@ def services_to_restart(conn, old_attrs={}, new_attrs={}):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if service in services_to_time.keys():
|
if service in services_to_time.keys():
|
||||||
start = services_to_time[service](attr)
|
for start in services_to_time[service](attr):
|
||||||
#print "%s,%s,%s" % (service, arg, start)
|
service_to_restart(conn, service, list(arg), start)
|
||||||
service_to_restart(conn, service, list(arg), start)
|
else:
|
||||||
|
service_to_restart(conn, service, list(arg), 0)
|
||||||
|
else:
|
||||||
|
service_to_restart(conn, service, [], 0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue