[trigger/firewall] On commence.

This commit is contained in:
Pierre-Elliott Bécue 2014-06-14 18:56:45 +02:00
parent bfd2f185e2
commit 51185c3b64
4 changed files with 161 additions and 6 deletions

View file

@ -15,7 +15,7 @@ import cranslib.clogger as clogger
import pika
import lc_ldap.attributs
logger = clogger.CLogger("trigger", "info")
logger = clogger.CLogger("trigger.event", "info")
class Event(cmb.BasicProducer):
"""
@ -128,6 +128,8 @@ def event(body=()):
"""
logger.info("Received message %s", body)
diff = diff_o_matic(body)
# À cette étape, on a un dico des attrs ayant subi une modif
@ -140,6 +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)
trigger_mac_ip(body, diff)
def trigger_mac_ip(body, diff):
@ -150,17 +153,18 @@ def trigger_mac_ip(body, diff):
# Régénération du DHCP :
if not macs[0]:
# Création d'une nouvelle machine.
to_send = {'add': (macs[1], ips[1], hostnames[1])}
dhcp = {'add': (macs[1], ips[1], hostnames[1])}
fw = {'add': (macs[1], ips[1])}
elif not macs[1]:
# Destruction d'une machine.
to_send = {'delete': (macs[0], ips[0])}
fw = {'delete': (macs[0], ips[0])}
else:
# Mise à jour.
to_send = {'update': (macs[0], ips[0], macs[1], ips[1], hostnames[1])}
fw = {'update': (macs[0], ips[0], macs[1], ips[1])}
trigger_send('dhcp', to_send)
# Régénération du parefeu.
trigger_send('mac_ip', to_send)
trigger_send('firewall_mac_ip', fw)
def trigger_send(ttype, to_send):
print "Sending trigger %s with %s" % (ttype, to_send)