[trigger] MetaService en place, et amélioration du débug
This commit is contained in:
parent
d29343392b
commit
a52ef72a54
8 changed files with 202 additions and 146 deletions
|
@ -15,57 +15,22 @@ it to regenerate what needs to.
|
|||
"""
|
||||
|
||||
import lc_ldap.shortcuts
|
||||
from gestion.trigger.host import record
|
||||
import gestion.config.trigger as trigger_config
|
||||
from gestion.trigger.services.service import BasicService
|
||||
import cranslib.clogger as clogger
|
||||
import gestion.config.firewall as firewall_config
|
||||
import gestion.trigger.firewall4.firewall4 as firewall4
|
||||
|
||||
logger = clogger.CLogger("trigger.firewall", "debug")
|
||||
logger = clogger.CLogger("trigger", "firewall", "debug", trigger_config.debug)
|
||||
|
||||
class FwFunFactory(object):
|
||||
"""Factory containing which function is part of the trigger set
|
||||
|
||||
"""
|
||||
|
||||
_meths = {}
|
||||
|
||||
@classmethod
|
||||
def register(cls, key, value):
|
||||
"""Stores in factory the function name and its value
|
||||
|
||||
"""
|
||||
cls._meths[key] = value
|
||||
|
||||
@classmethod
|
||||
def get(cls, key):
|
||||
"""Gets what is stored
|
||||
|
||||
"""
|
||||
return cls._meths.get(key, None)
|
||||
|
||||
def fwrecord(function):
|
||||
"""Records function in FwFunFactory
|
||||
|
||||
"""
|
||||
FwFunFactory.register(function.func_name, function)
|
||||
|
||||
def fwcall(fwfun):
|
||||
"""Calls in function from FwFunFactory
|
||||
|
||||
"""
|
||||
return FwFunFactory.get(fwfun)
|
||||
|
||||
@record
|
||||
class firewall(BasicService):
|
||||
class Firewall(BasicService):
|
||||
"""Firewall service that handles any modification in the firewall.
|
||||
|
||||
"""
|
||||
|
||||
# Class lookup table to define which changes call which function.
|
||||
changes_trigger = {
|
||||
lc_ldap.attributs.macAddress.ldap_name: (firewall.send_mac_ip,),
|
||||
lc_ldap.attributs.ipHostNumber.ldap_name: (firewall.send_mac_ip,),
|
||||
lc_ldap.attributs.macAddress.ldap_name: ('send_mac_ip',),
|
||||
lc_ldap.attributs.ipHostNumber.ldap_name: ('send_mac_ip',),
|
||||
}
|
||||
|
||||
@classmethod
|
||||
|
@ -98,19 +63,19 @@ class firewall(BasicService):
|
|||
return
|
||||
(service, data) = body
|
||||
logger.info("Calling service %s for data %r", service, data)
|
||||
fwcall(service)(data)
|
||||
getattr(cls, service)(data)
|
||||
|
||||
@fwrecord
|
||||
def mac_ip(body):
|
||||
host_fw = firewall4.firewall()
|
||||
if body and isinstance(body, dict):
|
||||
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", []):
|
||||
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", []):
|
||||
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)
|
||||
@classmethod
|
||||
def mac_ip(cls, body):
|
||||
host_fw = firewall4.firewall()
|
||||
if body and isinstance(body, dict):
|
||||
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", []):
|
||||
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", []):
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue