[gen_conf] stripping trailing whitespaces
darcs-hash:20090225185117-bd074-1c099460d115451d0adb95e5f873bde97b87317a.gz
This commit is contained in:
parent
95b51ff7e3
commit
dd6fb093d6
2 changed files with 39 additions and 41 deletions
|
@ -11,7 +11,7 @@ import sys, os, signal
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
|
|
||||||
import time, commands
|
import time, commands
|
||||||
from affich_tools import *
|
from affich_tools import *
|
||||||
from lock import *
|
from lock import *
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
@ -27,23 +27,23 @@ class gen_config :
|
||||||
def lockname(self):
|
def lockname(self):
|
||||||
"""Nom du lock"""
|
"""Nom du lock"""
|
||||||
return str(self.__class__)
|
return str(self.__class__)
|
||||||
|
|
||||||
def lock(self) :
|
def lock(self) :
|
||||||
""" Lock le service courant """
|
""" Lock le service courant """
|
||||||
if not self._locked :
|
if not self._locked :
|
||||||
make_lock(self.lockname(),'')
|
make_lock(self.lockname(),'')
|
||||||
self._locked = 1
|
self._locked = 1
|
||||||
|
|
||||||
def unlock(self) :
|
def unlock(self) :
|
||||||
""" Supression du lock """
|
""" Supression du lock """
|
||||||
if self._locked : remove_lock(self.lockname())
|
if self._locked : remove_lock(self.lockname())
|
||||||
|
|
||||||
def __del__(self) :
|
def __del__(self) :
|
||||||
# Au cas où...
|
# Au cas où...
|
||||||
self.unlock()
|
self.unlock()
|
||||||
|
|
||||||
def _restore(self) :
|
def _restore(self) :
|
||||||
""" Affichage d'une erreur et du traceback si debug
|
""" Affichage d'une erreur et du traceback si debug
|
||||||
Puis restauration des fichers """
|
Puis restauration des fichers """
|
||||||
print ERREUR
|
print ERREUR
|
||||||
if self.debug :
|
if self.debug :
|
||||||
|
@ -52,53 +52,53 @@ class gen_config :
|
||||||
# Restauration
|
# Restauration
|
||||||
for nom, f in self.__restore.items() :
|
for nom, f in self.__restore.items() :
|
||||||
os.system('cp -f %s %s' % ( f.name, nom ) )
|
os.system('cp -f %s %s' % ( f.name, nom ) )
|
||||||
|
|
||||||
def _open_conf(self,nom,comment=None) :
|
def _open_conf(self,nom,comment=None) :
|
||||||
""" Créé un fichier
|
""" Créé un fichier
|
||||||
si comment est fourni, insère une entète qui utilisera le caractère
|
si comment est fourni, insère une entète qui utilisera le caractère
|
||||||
de commentaire fourni
|
de commentaire fourni
|
||||||
|
|
||||||
copie l'ancien fichier dans un fichier temporaire pour permettre
|
copie l'ancien fichier dans un fichier temporaire pour permettre
|
||||||
la restauration en cas d'échec de la configuration
|
la restauration en cas d'échec de la configuration
|
||||||
|
|
||||||
Retourne le descripteur du fichier """
|
Retourne le descripteur du fichier """
|
||||||
|
|
||||||
f = NamedTemporaryFile()
|
f = NamedTemporaryFile()
|
||||||
os.system('cp %s %s 2> /dev/null' % ( nom, f.name ) )
|
os.system('cp %s %s 2> /dev/null' % ( nom, f.name ) )
|
||||||
self.__restore[nom] = f
|
self.__restore[nom] = f
|
||||||
|
|
||||||
fd = open(nom, 'w')
|
fd = open(nom, 'w')
|
||||||
|
|
||||||
if comment :
|
if comment :
|
||||||
e = """***********************************************************
|
e = """***********************************************************
|
||||||
Ce fichier est genere par les scripts de %s
|
Ce fichier est genere par les scripts de %s
|
||||||
Les donnees proviennent de la base LDAP et de la conf
|
Les donnees proviennent de la base LDAP et de la conf
|
||||||
presente au debut du script.
|
presente au debut du script.
|
||||||
|
|
||||||
Generation : %s
|
Generation : %s
|
||||||
Fichier : %s
|
Fichier : %s
|
||||||
|
|
||||||
NE PAS EDITER
|
NE PAS EDITER
|
||||||
|
|
||||||
***********************************************************""" % \
|
***********************************************************""" % \
|
||||||
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
(__name__, time.strftime('%A %d %B %Y %H:%M'), nom )
|
||||||
|
|
||||||
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
e = comment + e.replace('\n', '\n%s' % comment) + '\n'
|
||||||
fd.write(e)
|
fd.write(e)
|
||||||
|
|
||||||
return fd
|
return fd
|
||||||
|
|
||||||
def gen_conf(self) :
|
def gen_conf(self) :
|
||||||
""" Génération des fichiers de conf, retourne False si erreur """
|
""" Génération des fichiers de conf, retourne False si erreur """
|
||||||
self.lock()
|
self.lock()
|
||||||
self.anim = anim('\tgénération fichiers')
|
self.anim = anim('\tgénération fichiers')
|
||||||
try :
|
try :
|
||||||
warn = self._gen()
|
warn = self._gen()
|
||||||
if warn :
|
if warn :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
print WARNING
|
print WARNING
|
||||||
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
if self.debug : sys.stderr.write(warn.encode("ISO-8859-15"))
|
||||||
else :
|
else :
|
||||||
self.anim.reinit()
|
self.anim.reinit()
|
||||||
print OK
|
print OK
|
||||||
self.unlock()
|
self.unlock()
|
||||||
|
@ -108,7 +108,7 @@ class gen_config :
|
||||||
self._restore()
|
self._restore()
|
||||||
self.unlock()
|
self.unlock()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def restart(self) :
|
def restart(self) :
|
||||||
""" Redémarrage du service concerné """
|
""" Redémarrage du service concerné """
|
||||||
if not self.restart_cmd : return
|
if not self.restart_cmd : return
|
||||||
|
@ -125,9 +125,9 @@ class gen_config :
|
||||||
else :
|
else :
|
||||||
print OK
|
print OK
|
||||||
self.unlock()
|
self.unlock()
|
||||||
|
|
||||||
def reconfigure(self) :
|
def reconfigure(self) :
|
||||||
""" Génère les fichiers puis redémarre le service
|
""" Génère les fichiers puis redémarre le service
|
||||||
si la génération c'est bien passée """
|
si la génération c'est bien passée """
|
||||||
cprint(u'Reconfiguration %s :' % self.__str__(), 'gras')
|
cprint(u'Reconfiguration %s :' % self.__str__(), 'gras')
|
||||||
if self.gen_conf() :
|
if self.gen_conf() :
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
# -*- coding: iso-8859-15 -*-
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
""" Génération de la configuration pour le dhcp
|
""" Génération de la configuration pour le dhcp
|
||||||
|
|
||||||
Copyright (C) Frédéric Pauget
|
Copyright (C) Frédéric Pauget
|
||||||
Licence : GPLv2
|
Licence : GPLv2
|
||||||
|
@ -13,15 +13,14 @@ from ldap_crans import hostname
|
||||||
|
|
||||||
class dhcp(gen_config) :
|
class dhcp(gen_config) :
|
||||||
""" Génération du fichier de configuration pour dhcpd (DHCPD_CONF)
|
""" Génération du fichier de configuration pour dhcpd (DHCPD_CONF)
|
||||||
Le fichier comporte une partie par réseau servi, chaque réseau
|
Le fichier comporte une partie par réseau servi, chaque réseau
|
||||||
servi doit être une clef du dictionnaire reseaux, la valeur correspondante
|
servi doit être une clef du dictionnaire reseaux, la valeur correspondante
|
||||||
est une chaine décrivant les options spécifiques à ce réseau.
|
est une chaine décrivant les options spécifiques à ce réseau.
|
||||||
Les options communes sont celles de base_dhcp.
|
Les options communes sont celles de base_dhcp.
|
||||||
|
|
||||||
Chaque machines possède ensuite une entrée de la forme de host_template
|
Chaque machines possède ensuite une entrée de la forme de host_template
|
||||||
"""
|
"""
|
||||||
######################################PARTIE DE CONFIGURATION
|
######################################PARTIE DE CONFIGURATION
|
||||||
|
|
||||||
# Fichier à écire
|
# Fichier à écire
|
||||||
if hostname == 'rouge' :
|
if hostname == 'rouge' :
|
||||||
DHCPD_CONF = '/etc/dhcp3/dhcpd.conf'
|
DHCPD_CONF = '/etc/dhcp3/dhcpd.conf'
|
||||||
|
@ -69,7 +68,7 @@ option option-119 code 119 = text ;
|
||||||
option option-119 "crans.org wifi.crans.org";"""
|
option option-119 "crans.org wifi.crans.org";"""
|
||||||
}
|
}
|
||||||
elif hostname == 'rouge':
|
elif hostname == 'rouge':
|
||||||
reseaux = { '138.231.136.0/21' :
|
reseaux = { '138.231.136.0/21' :
|
||||||
"""authoritative;
|
"""authoritative;
|
||||||
option routers 138.231.136.4;
|
option routers 138.231.136.4;
|
||||||
option domain-name-servers 138.231.136.3, 138.231.136.9, 138.231.136.10;
|
option domain-name-servers 138.231.136.3, 138.231.136.9, 138.231.136.10;
|
||||||
|
@ -124,8 +123,8 @@ subnet %(network)s netmask %(netmask)s {
|
||||||
option root-path "/opt/ltsp/powerpc";
|
option root-path "/opt/ltsp/powerpc";
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
### Verbosité
|
### Verbosité
|
||||||
# Si =1 ralera (chaine warnings) si machines hors zone trouvée
|
# Si =1 ralera (chaine warnings) si machines hors zone trouvée
|
||||||
# Si =0 ralera seulement si réseau vide
|
# Si =0 ralera seulement si réseau vide
|
||||||
verbose = 1
|
verbose = 1
|
||||||
|
@ -138,18 +137,17 @@ subnet %(network)s netmask %(netmask)s {
|
||||||
restart_cmd = '/etc/init.d/dhcp3-server restart'
|
restart_cmd = '/etc/init.d/dhcp3-server restart'
|
||||||
else:
|
else:
|
||||||
restart_cmd = 'true'
|
restart_cmd = 'true'
|
||||||
|
|
||||||
######################################FIN PARTIE DE CONFIGURATION
|
######################################FIN PARTIE DE CONFIGURATION
|
||||||
|
|
||||||
def __str__(self) :
|
def __str__(self) :
|
||||||
return 'dhcp'
|
return 'dhcp'
|
||||||
|
|
||||||
def _gen(self) :
|
def _gen(self) :
|
||||||
warnings =''
|
warnings =''
|
||||||
|
|
||||||
### Construction de la partie du fichier contenant les machines
|
### Construction de la partie du fichier contenant les machines
|
||||||
hosts={}
|
hosts={}
|
||||||
|
|
||||||
self.anim.iter=len(self.machines)
|
self.anim.iter=len(self.machines)
|
||||||
for machine in self.machines :
|
for machine in self.machines :
|
||||||
self.anim.cycle()
|
self.anim.cycle()
|
||||||
|
@ -168,7 +166,7 @@ subnet %(network)s netmask %(netmask)s {
|
||||||
try : hosts[net] += host_template % d
|
try : hosts[net] += host_template % d
|
||||||
except : hosts[net] = host_template % d
|
except : hosts[net] = host_template % d
|
||||||
t = 1
|
t = 1
|
||||||
|
|
||||||
### Ecriture du fichier
|
### Ecriture du fichier
|
||||||
fd = self._open_conf(self.DHCPD_CONF,'#')
|
fd = self._open_conf(self.DHCPD_CONF,'#')
|
||||||
fd.write(self.base_conf)
|
fd.write(self.base_conf)
|
||||||
|
@ -179,9 +177,9 @@ subnet %(network)s netmask %(netmask)s {
|
||||||
d = param(net)
|
d = param(net)
|
||||||
d['OPTIONS_RESEAU'] = options
|
d['OPTIONS_RESEAU'] = options
|
||||||
d['HOSTs'] = hosts[net]
|
d['HOSTs'] = hosts[net]
|
||||||
|
|
||||||
fd.write(self.base_dhcp % d)
|
fd.write(self.base_dhcp % d)
|
||||||
|
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
return warnings
|
return warnings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue