[trigger] Correctifs mineurs
This commit is contained in:
parent
7bfe23a6ec
commit
334bac5aa2
3 changed files with 26 additions and 22 deletions
|
@ -7,25 +7,25 @@
|
||||||
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
# Author : Pierre-Elliott Bécue <becue@crans.org>
|
||||||
# Licence : GPLv3
|
# Licence : GPLv3
|
||||||
|
|
||||||
import lc_ldap.shortcuts
|
|
||||||
import gestion.config.trigger as trigger_config
|
|
||||||
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 socket
|
||||||
import gestion.affichage as affichage
|
|
||||||
import os
|
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
|
import struct
|
||||||
|
|
||||||
|
import gestion.config.trigger as trigger_config
|
||||||
|
import cranslib.clogger as clogger
|
||||||
logger = clogger.CLogger("trigger", "dhcp", "debug", trigger_config.debug)
|
logger = clogger.CLogger("trigger", "dhcp", "debug", trigger_config.debug)
|
||||||
|
|
||||||
hostname = socket.gethostname().split(".")[0] + ".adm.crans.org"
|
hostname = socket.gethostname().split(".")[0] + ".adm.crans.org"
|
||||||
ldap_conn = lc_ldap.shortcuts.lc_ldap_readonly()
|
|
||||||
|
import lc_ldap.shortcuts
|
||||||
|
from gestion.trigger.services.service import BasicService
|
||||||
|
from cranslib.conffile import ConfFile
|
||||||
|
import gestion.config.dhcp as dhcp_config
|
||||||
|
import gestion.secrets_new as secrets_new
|
||||||
|
import gestion.affichage as affichage
|
||||||
|
import gestion.iptools as iptools
|
||||||
|
from gestion.trigger.pypureomapi import pack_ip, pack_mac, OMAPI_OP_UPDATE
|
||||||
|
from gestion.trigger.pypureomapi import Omapi, OmapiMessage
|
||||||
|
|
||||||
|
|
||||||
class Dhcp(BasicService):
|
class Dhcp(BasicService):
|
||||||
|
@ -40,7 +40,8 @@ class Dhcp(BasicService):
|
||||||
}
|
}
|
||||||
|
|
||||||
dhcp_omapi_keyname = None
|
dhcp_omapi_keyname = None
|
||||||
dhcp_omapi_key = None #secrets_new.get("dhcp_omapi_keys")[hostname]
|
dhcp_omapi_key = None
|
||||||
|
ldap_conn = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_mac_ip(cls, body, diff):
|
def send_mac_ip(cls, body, diff):
|
||||||
|
@ -91,7 +92,7 @@ class Dhcp(BasicService):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
affichage.prettyDoin("Chargement des machines", "...")
|
affichage.prettyDoin("Chargement des machines", "...")
|
||||||
machines = ldap_conn.allMachines()
|
machines = cls.ldap_conn.allMachines()
|
||||||
affichage.prettyDoin("Chargement des machines", "Ok")
|
affichage.prettyDoin("Chargement des machines", "Ok")
|
||||||
animation = affichage.Animation(texte="Génération de la configuration",
|
animation = affichage.Animation(texte="Génération de la configuration",
|
||||||
nb_cycles=len(machines),
|
nb_cycles=len(machines),
|
||||||
|
@ -137,7 +138,7 @@ class Dhcp(BasicService):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_secrets(cls):
|
def check_params(cls):
|
||||||
"""This method allows lazy evaluation for dhcp_omapi_keyname
|
"""This method allows lazy evaluation for dhcp_omapi_keyname
|
||||||
and dhcp_omapi_key, since event imports all services. This is actually
|
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
|
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")
|
cls.dhcp_omapi_keyname = secrets_new.get("dhcp_omapi_keyname")
|
||||||
if cls.dhcp_omapi_key is None:
|
if cls.dhcp_omapi_key is None:
|
||||||
cls.dhcp_omapi_key = secrets_new.get("dhcp_omapi_keys")[hostname]
|
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
|
@classmethod
|
||||||
def add_dhcp_host(cls, mac, ip, name=None):
|
def add_dhcp_host(cls, mac, ip, name=None):
|
||||||
"""Adds a dhcp host using omapi
|
"""Adds a dhcp host using omapi
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cls.check_secrets()
|
cls.check_params()
|
||||||
|
|
||||||
if '<automatique>' in [ip, mac]:
|
if '<automatique>' in [ip, mac]:
|
||||||
return
|
return
|
||||||
|
@ -175,7 +178,7 @@ class Dhcp(BasicService):
|
||||||
"""Deletes dhcp host using omapi
|
"""Deletes dhcp host using omapi
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cls.check_secrets()
|
cls.check_params()
|
||||||
|
|
||||||
if '<automatique>' in [ip, mac]:
|
if '<automatique>' in [ip, mac]:
|
||||||
return
|
return
|
||||||
|
|
|
@ -133,7 +133,7 @@ def compare_lists(list1, list2):
|
||||||
|
|
||||||
return moins, plus
|
return moins, plus
|
||||||
|
|
||||||
class event(BasicService):
|
class Event(BasicService):
|
||||||
"""Event service class. It extends BasicService, but should not implement
|
"""Event service class. It extends BasicService, but should not implement
|
||||||
any change trigger, since it's this service which is designed to call
|
any change trigger, since it's this service which is designed to call
|
||||||
change triggers of other services.
|
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.
|
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 lc_ldap.shortcuts
|
||||||
|
|
||||||
import gestion.config.trigger as trigger_config
|
import gestion.config.trigger as trigger_config
|
||||||
from gestion.trigger.services.service import BasicService
|
from gestion.trigger.services.service import BasicService
|
||||||
import cranslib.clogger as clogger
|
|
||||||
import gestion.trigger.firewall4.firewall4 as firewall4
|
import gestion.trigger.firewall4.firewall4 as firewall4
|
||||||
|
|
||||||
logger = clogger.CLogger("trigger", "firewall", "debug", trigger_config.debug)
|
|
||||||
|
|
||||||
class Firewall(BasicService):
|
class Firewall(BasicService):
|
||||||
"""Firewall service that handles any modification in the firewall.
|
"""Firewall service that handles any modification in the firewall.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue