Readme à jour, et quelques modifications sur les noms de variables.

This commit is contained in:
Pierre-Elliott Bécue 2015-03-10 21:06:16 +01:00
parent f228493399
commit 4bc4cb7abe
8 changed files with 152 additions and 102 deletions

View file

@ -42,31 +42,31 @@ else:
ldap_conn = None
@record_service()
def dhcp(ob_id, body=None):
"""Regenerates dhcp service taking body into account.
def dhcp(ob_id, operations=None):
"""Regenerates dhcp service taking operations into account.
"""
# http://satyajit.ranjeev.in/2012/01/12/python--dangerous-default-value-as-argument.html
# dict are referenced.
if body is None:
body = {}
if operations is None:
operations = {}
if body and isinstance(body, dict):
for (mac, ip, name) in body.get("add", []):
if operations and isinstance(operations, dict):
for (mac, ip, name) in operations.get("add", []):
logger.info("Updating DHCP db by adding %s, %s, %s", mac, ip, name)
# XXX - Uncommend this when we need to start prod
# add_dhcp_host(mac, ip, name)
for (mac, ip) in body.get("delete", []):
for (mac, ip) in operations.get("delete", []):
logger.info("Updating DHCP db by deleting %s, %s", mac, ip)
# XXX - Uncommend this when we need to start prod
# delete_dhcp_host(mac, ip)
for (rmac, rip, mac, ip, name) in body.get("update", []):
for (rmac, rip, mac, ip, name) in operations.get("update", []):
logger.info("Updating DHCP db by modifying %s, %s to %s, %s, %s", rmac, rip, mac, ip, name)
# XXX - Uncommend this when we need to start prod
# delete_dhcp_host(rmac, rip)
# add_dhcp_host(mac, ip, name)
elif body == True:
elif operations == True:
hosts = {}
host_template = """
host %(nom)s {

View file

@ -261,13 +261,13 @@ def event(ob_id, before, after, more):
# Compute the whole list of messages. This returns a list of 2-tuples. We remove None messages, which
# should not occcur... But, whatever.
msgs_to_send = [msg for msg in [function(ob_id, (before, after), diff) for function in functions] if msg is not None]
msgs_to_send = [msg for msg in [function(ob_id, (before, after), diff, more) for function in functions] if msg is not None]
LOGGER.debug("[%r] in service event, messages are %r.", ob_id, msgs_to_send)
for msg in msgs_to_send:
service_name, body, pos = msg[0], msg[1], msg[2]
LOGGER.info("[%r] Adding %r on the EventTracker", ob_id, (pos, service_name, body))
EventTracker.record_event_to_chain(ob_id, pos, service_name, body)
service_name, operations, pos = msg[0], msg[1], msg[2]
LOGGER.info("[%r] Adding %r on the EventTracker", ob_id, (pos, service_name, operations))
EventTracker.record_event_to_chain(ob_id, pos, service_name, operations)
# Sends the first wave on the way.
todo = EventTracker.get_off_record(ob_id)
@ -276,8 +276,8 @@ def event(ob_id, before, after, more):
# XXX - uncomment this when in production
trigger_send(*msg)
def trigger_send(ob_id, routing_key, body):
def trigger_send(ob_id, routing_key, operations):
"""Sends a message via civet/trigger"""
body = tuple([ob_id] + [body])
PRODUCER.send_message("trigger.%s" % (routing_key,), body)
msg = tuple([ob_id] + [operations])
PRODUCER.send_message("trigger.%s" % (routing_key,), msg)

View file

@ -42,29 +42,29 @@ def fwrecord(fun):
FwFactory.register(fun.func_name, fun)
@record_service()
def firewall(ob_id, body=()):
def firewall(ob_id, operations=()):
"""Regens the specific service
"""
if len(body) != 2:
logger.warning("Received body %r, this format is incorrect, discarding.", body)
if len(operations) != 2:
logger.warning("Received operations %r, this format is incorrect, discarding.", operations)
return
(service, data) = body
(service, data) = operations
logger.info("Calling service %s for data %r", service, data)
# XXX - Uncomment when in prod
#FwFactory.get(service)(data)
@fwrecord
def mac_ip(body):
def mac_ip(operations):
host_fw = firewall4.firewall()
if body and isinstance(body, dict):
for (mac, ip) in body.get("add", []):
if operations and isinstance(operations, dict):
for (mac, ip) in operations.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 operations.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 operations.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)

View file

@ -24,14 +24,12 @@ from gestion.trigger.host import record_service
import gestion.trigger.firewall4.firewall4 as firewall4
@record_service()
def secours(ob_id, body=()):
def secours(ob_id, operations=()):
"""Regens the specific service
"""
if len(body) != 2:
logger.warning("Received body %r, this format is incorrect, discarding.", body)
if len(operations) != 2:
logger.warning("Received operations %r, this format is incorrect, discarding.", operations)
return
(service, data) = body
(service, data) = operations
logger.info("Calling service %s for data %r", service, data)
# XXX - Uncomment when in prod
#FwFactory.get(service)(data)