On splitte services et parsers (qui ne sont utilisés que par civet.event)
This commit is contained in:
parent
f24e463da5
commit
06095f5580
7 changed files with 96 additions and 46 deletions
4
gestion/trigger/parsers/__init__.py
Normal file
4
gestion/trigger/parsers/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Nauthing
|
40
gestion/trigger/parsers/dhcp.py
Normal file
40
gestion/trigger/parsers/dhcp.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash /usr/scripts/python.sh
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# DHCP's trigger parser.
|
||||
#
|
||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||
# Licence : GPLv3
|
||||
# Date : 19/11/2014
|
||||
#
|
||||
# TODO : Take care of each XXX or TODO and think about updating
|
||||
# gestion/config/dhcp when submitting for production, because
|
||||
# of .test files.
|
||||
"""
|
||||
Handles the parser for trigger about dhcp service
|
||||
This currently is used for mac/IP updates of LDAP database.
|
||||
"""
|
||||
|
||||
import lc_ldap.attributs
|
||||
from gestion.trigger.host import record_parser
|
||||
|
||||
@record_parser(lc_ldap.attributs.macAddress.ldap_name, lc_ldap.attributs.ipHostNumber.ldap_name)
|
||||
def send_mac_ip(body, diff):
|
||||
"""Computes mac_ip data to send from body and diff
|
||||
|
||||
"""
|
||||
macs = tuple([body[i].get(lc_ldap.attributs.macAddress.ldap_name, [''])[0] for i in xrange(1, 3)])
|
||||
ips = tuple([body[i].get(lc_ldap.attributs.ipHostNumber.ldap_name, [''])[0] for i in xrange(1, 3)])
|
||||
hostnames = tuple([body[i].get(lc_ldap.attributs.host.ldap_name, [''])[0] for i in xrange(1, 3)])
|
||||
|
||||
# Régénération du DHCP :
|
||||
if not macs[0]:
|
||||
# Création d'une nouvelle machine.
|
||||
dhcp_dict = {'add': [(macs[1], ips[1], hostnames[1])]}
|
||||
elif not macs[1]:
|
||||
# Destruction d'une machine.
|
||||
dhcp_dict = {'delete': [(macs[0], ips[0])]}
|
||||
else:
|
||||
# Mise à jour.
|
||||
dhcp_dict = {'update': [(macs[0], ips[0], macs[1], ips[1], hostnames[1])]}
|
||||
return ("dhcp", dhcp_dict)
|
12
gestion/trigger/parsers/event.py
Normal file
12
gestion/trigger/parsers/event.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!//usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Parser for event service. Contains nothing.
|
||||
#
|
||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||
# License : GPLv3
|
||||
# Date : 19/11/2014
|
||||
"""
|
||||
This parser is not usefull, but still will be imported by service event.py
|
||||
on civet.
|
||||
"""
|
35
gestion/trigger/parsers/firewall.py
Normal file
35
gestion/trigger/parsers/firewall.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash /usr/scripts/python.sh
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Parser for firewall service.
|
||||
#
|
||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||
# Licence : GPLv3
|
||||
# Date : 15/06/2014
|
||||
"""
|
||||
This is the parser for firewall service.
|
||||
"""
|
||||
|
||||
import lc_ldap.attributs
|
||||
from gestion.trigger.host import record_parser
|
||||
|
||||
@record_parser(lc_ldap.attributs.macAddress.ldap_name, lc_ldap.attributs.ipHostNumber.ldap_name)
|
||||
def send_mac_ip(body, diff):
|
||||
"""Computes mac_ip data to send from body and diff
|
||||
|
||||
"""
|
||||
macs = tuple([body[i].get(lc_ldap.attributs.macAddress.ldap_name, [''])[0] for i in xrange(1, 3)])
|
||||
ips = tuple([body[i].get(lc_ldap.attributs.ipHostNumber.ldap_name, [''])[0] for i in xrange(1, 3)])
|
||||
|
||||
# Mise à jour du parefeu mac_ip
|
||||
if not macs[0]:
|
||||
# Création d'une nouvelle machine.
|
||||
fw = {'add': [(macs[1], ips[1])]}
|
||||
elif not macs[1]:
|
||||
# Destruction d'une machine.
|
||||
fw = {'delete': [(macs[0], ips[0])]}
|
||||
else:
|
||||
# Mise à jour.
|
||||
fw = {'update': [(macs[0], ips[0], macs[1], ips[1])]}
|
||||
return ("firewall", ("mac_ip", fw))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue