[trigger] Bugfix pour que le tout marche bien ensemble.
This commit is contained in:
parent
f41ab72706
commit
4e90bd023b
3 changed files with 17 additions and 15 deletions
|
@ -93,11 +93,11 @@ def dhcp(body={}):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if body and isinstance(body, dict):
|
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)
|
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)
|
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)
|
delete_dhcp_host(rmac, rip)
|
||||||
add_dhcp_host(mac, ip, name)
|
add_dhcp_host(mac, ip, name)
|
||||||
elif body == True:
|
elif body == True:
|
||||||
|
|
|
@ -142,7 +142,7 @@ def event(body=()):
|
||||||
|
|
||||||
# Si la mac ou l'IP a changé…
|
# 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):
|
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)
|
trigger_mac_ip(body, diff)
|
||||||
|
|
||||||
def 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 :
|
# Régénération du DHCP :
|
||||||
if not macs[0]:
|
if not macs[0]:
|
||||||
# Création d'une nouvelle machine.
|
# Création d'une nouvelle machine.
|
||||||
dhcp = {'add': (macs[1], ips[1], hostnames[1])}
|
dhcp = {'add': [(macs[1], ips[1], hostnames[1])]}
|
||||||
fw = {'add': (macs[1], ips[1])}
|
fw = {'add': [(macs[1], ips[1])]}
|
||||||
elif not macs[1]:
|
elif not macs[1]:
|
||||||
# Destruction d'une machine.
|
# Destruction d'une machine.
|
||||||
dhcp = {'delete': (macs[0], ips[0])}
|
dhcp = {'delete': [(macs[0], ips[0])]}
|
||||||
fw = {'delete': (macs[0], ips[0])}
|
fw = {'delete': [(macs[0], ips[0])]}
|
||||||
else:
|
else:
|
||||||
# Mise à jour.
|
# Mise à jour.
|
||||||
dhcp = {'update': (macs[0], ips[0], macs[1], ips[1], hostnames[1])}
|
dhcp = {'update': [(macs[0], ips[0], macs[1], ips[1], hostnames[1])]}
|
||||||
fw = {'update': (macs[0], ips[0], macs[1], ips[1])}
|
fw = {'update': [(macs[0], ips[0], macs[1], ips[1])]}
|
||||||
logger.info("Sending DHCP trigger with body %r", dhcp)
|
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)
|
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))
|
trigger_send("firewall", ("mac_ip", fw))
|
||||||
logger.info("trigger_mac_ip done.")
|
logger.info("trigger_mac_ip done.")
|
||||||
|
|
||||||
def trigger_send(routing_key, body):
|
def trigger_send(routing_key, body):
|
||||||
sender = Event("civet")
|
sender = Event("civet")
|
||||||
sender.send_message(routing_key, body)
|
sender.send_message("trigger.%s" % (routing_key,), body)
|
||||||
|
|
|
@ -52,13 +52,13 @@ def firewall(body=()):
|
||||||
def mac_ip(body):
|
def mac_ip(body):
|
||||||
host_fw = firewall4.firewall()
|
host_fw = firewall4.firewall()
|
||||||
if body and isinstance(body, dict):
|
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)
|
logger.info("Adding mac_ip %s,%s", mac, ip)
|
||||||
host_fw.mac_ip_append(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)
|
logger.info("Removing mac_ip %s,%s", mac, ip)
|
||||||
host_fw.mac_ip_remove(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)
|
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_remove(rmac, rip)
|
||||||
host_fw.mac_ip_append(mac, ip)
|
host_fw.mac_ip_append(mac, ip)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue