[trigger] Bugfix pour que le tout marche bien ensemble.

This commit is contained in:
Pierre-Elliott Bécue 2014-06-15 00:54:03 +02:00
parent f41ab72706
commit 4e90bd023b
3 changed files with 17 additions and 15 deletions

View file

@ -142,7 +142,7 @@ def event(body=()):
# Si la mac ou l'IP a changé…
if diff.has_key(lc_ldap.attributs.ipHostNumber.ldap_name) or diff.has_key(lc_ldap.attributs.macAddress.ldap_name):
logger.info("Detected MAC or IP update, calling trigger_mac_ip…", body)
logger.info("Detected MAC or IP update, calling trigger_mac_ip…")
trigger_mac_ip(body, diff)
def trigger_mac_ip(body, diff):
@ -153,22 +153,24 @@ def trigger_mac_ip(body, diff):
# Régénération du DHCP :
if not macs[0]:
# Création d'une nouvelle machine.
dhcp = {'add': (macs[1], ips[1], hostnames[1])}
fw = {'add': (macs[1], ips[1])}
dhcp = {'add': [(macs[1], ips[1], hostnames[1])]}
fw = {'add': [(macs[1], ips[1])]}
elif not macs[1]:
# Destruction d'une machine.
dhcp = {'delete': (macs[0], ips[0])}
fw = {'delete': (macs[0], ips[0])}
dhcp = {'delete': [(macs[0], ips[0])]}
fw = {'delete': [(macs[0], ips[0])]}
else:
# Mise à jour.
dhcp = {'update': (macs[0], ips[0], macs[1], ips[1], hostnames[1])}
fw = {'update': (macs[0], ips[0], macs[1], ips[1])}
dhcp = {'update': [(macs[0], ips[0], macs[1], ips[1], hostnames[1])]}
fw = {'update': [(macs[0], ips[0], macs[1], ips[1])]}
logger.info("Sending DHCP trigger with body %r", dhcp)
trigger_send("dhcp", dhcp)
# XXX - Remove # when putting in production, needs further tests
#trigger_send("dhcp", dhcp)
logger.info("Sending firewall trigger for mac_ip with body %r", fw)
# XXX - Remove # when in prod, tested on 15/06/2014, functionnal.
trigger_send("firewall", ("mac_ip", fw))
logger.info("trigger_mac_ip done.")
def trigger_send(routing_key, body):
sender = Event("civet")
sender.send_message(routing_key, body)
sender.send_message("trigger.%s" % (routing_key,), body)