[trigger] Ajout d'un trigger mac_ip pour le parefeu.
This commit is contained in:
parent
31df6dc770
commit
f41ab72706
3 changed files with 62 additions and 16 deletions
|
@ -2,20 +2,63 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Service in charge of firewall for trigger.
|
||||
# Contains multiple subservices for each special
|
||||
# part of firewall.
|
||||
#
|
||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||
# Licence : GPLv3
|
||||
# Date : 15/06/2014
|
||||
|
||||
import lc_ldap.shortcuts
|
||||
from gestion.trigger.host import record
|
||||
import cranslib.clogger as clogger
|
||||
import gestion.config.dhcp as dhcp_config
|
||||
import gestion.secrets_new as secrets_new
|
||||
import socket
|
||||
import gestion.affichage as affichage
|
||||
import gestion.config.firewall as firewall_config
|
||||
import gestion.trigger.firewall4.firewall4 as firewall4
|
||||
import os
|
||||
import sys
|
||||
import gestion.iptools as iptools
|
||||
|
||||
logger = clogger.CLogger("trigger.firewall", "debug")
|
||||
hostname = socket.gethostname().split(".")[0] + ".adm.crans.org"
|
||||
|
||||
class FwFunFactory(object):
|
||||
"""Factory containing which function is part of the trigger set
|
||||
|
||||
"""
|
||||
|
||||
_meths = {}
|
||||
|
||||
@classmethod
|
||||
def register(cls, key, value):
|
||||
cls._meths[key] = value
|
||||
|
||||
@classmethod
|
||||
def get(cls, key):
|
||||
return cls._meths.get(key, None)
|
||||
|
||||
def fwrecord(function):
|
||||
FwFunFactory.register(function.func_name, function)
|
||||
|
||||
def fwcall(fwfun):
|
||||
return FwFunFactory.get(fwfun)
|
||||
|
||||
@record
|
||||
def firewall(body=()):
|
||||
if len(body) != 2:
|
||||
logger.warning("Received body %r, this format is incorrect, discarding.", body)
|
||||
(service, data) = body
|
||||
logger.info("Calling service %s for data %r", service, data)
|
||||
fwcall(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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue