[./gestion/gen_confs/dhcpd_new.py] Nouvelle version du script de génération du dhcp
darcs-hash:20090707223856-8fbb1-c4181336218768400991f6f519ef43e3f012e744.gz
This commit is contained in:
parent
21089cfdf2
commit
459311d1ad
1 changed files with 88 additions and 0 deletions
88
gestion/gen_confs/dhcpd_new.py
Executable file
88
gestion/gen_confs/dhcpd_new.py
Executable file
|
@ -0,0 +1,88 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
|
""" Génération de la configuration pour le dhcp
|
||||||
|
|
||||||
|
Copyright (C) Frédéric Pauget
|
||||||
|
Licence : GPLv2
|
||||||
|
"""
|
||||||
|
|
||||||
|
from iptools import AddrInNet
|
||||||
|
from gen_confs import gen_config
|
||||||
|
from ldap_crans import hostname
|
||||||
|
|
||||||
|
class dhcp(gen_config) :
|
||||||
|
""" Génération du fichier de déclaration des hosts.
|
||||||
|
Chaque réseau servi doit être une clef du dictionnaire reseaux,
|
||||||
|
la valeur correspondante est une chaine contenant le nom du fichier
|
||||||
|
associé à ce réseau.
|
||||||
|
|
||||||
|
Chaque machine possède ensuite une entrée de la forme de host_template.
|
||||||
|
"""
|
||||||
|
######################################PARTIE DE CONFIGURATION
|
||||||
|
# Fichier à écire
|
||||||
|
if hostname == 'sable':
|
||||||
|
restart_cmd = '/etc/init.d/dhcp3-server restart'
|
||||||
|
reseaux = { '138.231.136.0/21' : '/etc/dhcp3/generated/adherents.liste',
|
||||||
|
'10.42.0.0/16' : '/etc/dhcp3/generated/gratuit.liste' }
|
||||||
|
elif hostname == 'titanic':
|
||||||
|
restart_cmd = '/etc/init.d/dhcp3-server restart'
|
||||||
|
reseaux = { '10.2.9.0/24' : '/etc/dhcp3/generated/appartements.liste' }
|
||||||
|
|
||||||
|
host_template = """
|
||||||
|
host %(nom)s {
|
||||||
|
hardware ethernet %(mac)s;
|
||||||
|
fixed-address %(ip)s;
|
||||||
|
option host-name "%(nom)s";
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
host_template_ltsp_powerpc = """
|
||||||
|
host %(nom)s {
|
||||||
|
hardware ethernet %(mac)s;
|
||||||
|
fixed-address %(ip)s;
|
||||||
|
option host-name "%(nom)s";
|
||||||
|
next-server 138.231.136.98;
|
||||||
|
filename "yaboot";
|
||||||
|
option root-path "/opt/ltsp/powerpc";
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
### Verbosité
|
||||||
|
# Si =1 ralera (chaine warnings) si machines hors zone trouvée
|
||||||
|
# Si =0 ralera seulement si réseau vide
|
||||||
|
verbose = 1
|
||||||
|
|
||||||
|
######################################FIN PARTIE DE CONFIGURATION
|
||||||
|
def __str__(self) :
|
||||||
|
return 'dhcp'
|
||||||
|
|
||||||
|
def _gen(self) :
|
||||||
|
"""Construction de la liste des machines appartenant à un réseau
|
||||||
|
"""
|
||||||
|
|
||||||
|
warnings = ''
|
||||||
|
|
||||||
|
### Construction de la partie du fichier contenant les machines
|
||||||
|
hosts = {}
|
||||||
|
|
||||||
|
self.anim.iter = len(self.machines)
|
||||||
|
for machine in self.machines :
|
||||||
|
self.anim.cycle()
|
||||||
|
for net in self.reseaux.keys() :
|
||||||
|
if AddrInNet(machine.ip(), net) :
|
||||||
|
host_template = self.host_template
|
||||||
|
# variable pour remplir le template
|
||||||
|
d = { 'nom' : machine.nom().split('.')[0] , 'mac' : machine.mac() , 'ip' : machine.ip() }
|
||||||
|
try :
|
||||||
|
hosts[net] += host_template % d
|
||||||
|
except : hosts[net] = host_template % d
|
||||||
|
|
||||||
|
### Ecriture du fichier
|
||||||
|
for net, fichier in self.reseaux.items() :
|
||||||
|
fd0 = self._open_conf(fichier, '#')
|
||||||
|
if hosts.has_key(net):
|
||||||
|
fd0.write(hosts[net])
|
||||||
|
fd0.close()
|
||||||
|
|
||||||
|
return warnings
|
Loading…
Add table
Add a link
Reference in a new issue