Commit 334bac5a authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue
Browse files

[trigger] Correctifs mineurs

parent 7bfe23a6
......@@ -7,25 +7,25 @@
# Author : Pierre-Elliott Bécue <becue@crans.org>
# Licence : GPLv3
import lc_ldap.shortcuts
import socket
import os
import struct
import gestion.config.trigger as trigger_config
import cranslib.clogger as clogger
logger = clogger.CLogger("trigger", "dhcp", "debug", trigger_config.debug)
hostname = socket.gethostname().split(".")[0] + ".adm.crans.org"
import lc_ldap.shortcuts
from gestion.trigger.services.service import BasicService
from cranslib.conffile import ConfFile
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 os
import gestion.iptools as iptools
from gestion.trigger.pypureomapi import pack_ip, pack_mac, OMAPI_OP_UPDATE
from gestion.trigger.pypureomapi import Omapi, OmapiMessage
import struct
logger = clogger.CLogger("trigger", "dhcp", "debug", trigger_config.debug)
hostname = socket.gethostname().split(".")[0] + ".adm.crans.org"
ldap_conn = lc_ldap.shortcuts.lc_ldap_readonly()
class Dhcp(BasicService):
......@@ -40,7 +40,8 @@ class Dhcp(BasicService):
}
dhcp_omapi_keyname = None
dhcp_omapi_key = None #secrets_new.get("dhcp_omapi_keys")[hostname]
dhcp_omapi_key = None
ldap_conn = None
@classmethod
def send_mac_ip(cls, body, diff):
......@@ -91,7 +92,7 @@ class Dhcp(BasicService):
}
"""
affichage.prettyDoin("Chargement des machines", "...")
machines = ldap_conn.allMachines()
machines = cls.ldap_conn.allMachines()
affichage.prettyDoin("Chargement des machines", "Ok")
animation = affichage.Animation(texte="Génération de la configuration",
nb_cycles=len(machines),
......@@ -137,7 +138,7 @@ class Dhcp(BasicService):
raise
@classmethod
def check_secrets(cls):
def check_params(cls):
"""This method allows lazy evaluation for dhcp_omapi_keyname
and dhcp_omapi_key, since event imports all services. This is actually
the best lazy eval we can hope, since property won't work on
......@@ -148,13 +149,15 @@ class Dhcp(BasicService):
cls.dhcp_omapi_keyname = secrets_new.get("dhcp_omapi_keyname")
if cls.dhcp_omapi_key is None:
cls.dhcp_omapi_key = secrets_new.get("dhcp_omapi_keys")[hostname]
if cls.ldap_conn is None:
cls.ldap_conn = lc_ldap.shortcuts.lc_ldap_readonly()
@classmethod
def add_dhcp_host(cls, mac, ip, name=None):
"""Adds a dhcp host using omapi
"""
cls.check_secrets()
cls.check_params()
if '<automatique>' in [ip, mac]:
return
......@@ -175,7 +178,7 @@ class Dhcp(BasicService):
"""Deletes dhcp host using omapi
"""
cls.check_secrets()
cls.check_params()
if '<automatique>' in [ip, mac]:
return
......
......@@ -133,7 +133,7 @@ def compare_lists(list1, list2):
return moins, plus
class event(BasicService):
class Event(BasicService):
"""Event service class. It extends BasicService, but should not implement
any change trigger, since it's this service which is designed to call
change triggers of other services.
......
......@@ -14,14 +14,15 @@ is not designed to replace it, just to call specific functions from
it to regenerate what needs to.
"""
import cranslib.clogger as clogger
logger = clogger.CLogger("trigger", "firewall", "debug", trigger_config.debug)
import lc_ldap.shortcuts
import gestion.config.trigger as trigger_config
from gestion.trigger.services.service import BasicService
import cranslib.clogger as clogger
import gestion.trigger.firewall4.firewall4 as firewall4
logger = clogger.CLogger("trigger", "firewall", "debug", trigger_config.debug)
class Firewall(BasicService):
"""Firewall service that handles any modification in the firewall.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment