On splitte services et parsers (qui ne sont utilisés que par civet.event)

This commit is contained in:
Pierre-Elliott Bécue 2014-11-19 23:15:24 +01:00
parent f24e463da5
commit 06095f5580
7 changed files with 96 additions and 46 deletions

View file

@ -8,7 +8,7 @@
# Licence : GPLv3
# Date : 14/07/2014
#
# TODO : Take care of each XXX or TODO think about updating
# TODO : Take care of each XXX or TODO and think about updating
# gestion/config/dhcp when submitting for production, because
# of .test files.
@ -30,7 +30,7 @@ import gestion.secrets_new as secrets_new
import gestion.affichage as affichage
import gestion.iptools as iptools
from gestion.trigger.pypureomapi import pack_ip, pack_mac, OMAPI_OP_UPDATE, Omapi, OmapiMessage
from gestion.trigger.host import record_service, record_parser, TriggerFactory
from gestion.trigger.host import record_service
if "dhcp" in trigger_config.services[hostname]:
dhcp_omapi_keyname = secrets_new.get("dhcp_omapi_keyname")
@ -41,27 +41,6 @@ else:
dhcp_omapi_key = None
ldap_conn = None
@record_parser(lc_ldap.attributs.macAddress.ldap_name, lc_ldap.attributs.ipHostNumber.ldap_name)
def send_mac_ip(body, diff):
"""Computes mac_ip data to send from body and diff
"""
macs = tuple([body[i].get(lc_ldap.attributs.macAddress.ldap_name, [''])[0] for i in xrange(1, 3)])
ips = tuple([body[i].get(lc_ldap.attributs.ipHostNumber.ldap_name, [''])[0] for i in xrange(1, 3)])
hostnames = tuple([body[i].get(lc_ldap.attributs.host.ldap_name, [''])[0] for i in xrange(1, 3)])
# Régénération du DHCP :
if not macs[0]:
# Création d'une nouvelle machine.
dhcp_dict = {'add': [(macs[1], ips[1], hostnames[1])]}
elif not macs[1]:
# Destruction d'une machine.
dhcp_dict = {'delete': [(macs[0], ips[0])]}
else:
# Mise à jour.
dhcp_dict = {'update': [(macs[0], ips[0], macs[1], ips[1], hostnames[1])]}
return ("dhcp", dhcp_dict)
@record_service
def dhcp(body=None):
"""Regenerates dhcp service taking body into account.