[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

@ -93,11 +93,11 @@ def dhcp(body={}):
"""
if body and isinstance(body, dict):
for (mac, ip, name) in body.get("add", ()):
for (mac, ip, name) in body.get("add", []):
add_dhcp_host(mac, ip, name)
for (mac, ip) in body.get("delete", ()):
for (mac, ip) in body.get("delete", []):
delete_dhcp_host(mac, ip)
for (rmac, rip, mac, ip, name) in body.get("update", ()):
for (rmac, rip, mac, ip, name) in body.get("update", []):
delete_dhcp_host(rmac, rip)
add_dhcp_host(mac, ip, name)
elif body == True:

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)

View file

@ -52,13 +52,13 @@ def firewall(body=()):
def mac_ip(body):
host_fw = firewall4.firewall()
if body and isinstance(body, dict):
for (mac, ip) in body.get("add", ()):
for (mac, ip) in body.get("add", []):
logger.info("Adding mac_ip %s,%s", mac, ip)
host_fw.mac_ip_append(mac, ip)
for (mac, ip) in body.get("delete", ()):
for (mac, ip) in body.get("delete", []):
logger.info("Removing mac_ip %s,%s", mac, ip)
host_fw.mac_ip_remove(mac, ip)
for (rmac, rip, mac, ip) in body.get("update", ()):
for (rmac, rip, mac, ip) in body.get("update", []):
logger.info("Updating mac_ip %s,%s with %s,%s", rmac, rip, mac, ip)
host_fw.mac_ip_remove(rmac, rip)
host_fw.mac_ip_append(mac, ip)