
conflits de noms) darcs-hash:20041022015739-4ec08-45334af77434ef81c2132626dc33df0c27867214.gz
187 lines
7.6 KiB
Python
Executable file
187 lines
7.6 KiB
Python
Executable file
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
"""
|
|
Classe de génération du fichier de l'autostatus
|
|
Utilisé par generate.py
|
|
"""
|
|
|
|
# importation des fonctions et classes
|
|
|
|
import sys, os
|
|
sys.path.append('/usr/scripts/gestion')
|
|
from ldap_crans import crans
|
|
from gen_confs import gen_config
|
|
|
|
# définition de la classe
|
|
|
|
class autostatus(gen_config) :
|
|
|
|
# CONFIGURATION #
|
|
#################
|
|
|
|
# fichier de l'autostatus
|
|
CONFFILE = '/etc/autostatus/hosts'
|
|
|
|
# machines à ne pas mettre dans l'autostatus
|
|
exclude = ["non-configure.wifi.crans.org"]
|
|
|
|
# matrice du fichier d'autostatus
|
|
matrice = """
|
|
# Format : name address depend,list contact description
|
|
|
|
# routeurs vers l'extérieur #
|
|
#############################
|
|
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="+1"><B>Routeurs, dans l'ordre où ils sont entre le crans et l'extérieur :</font></b></TR>
|
|
|
|
komaz 138.231.136.4 none alerts@crans.org Notre routeur
|
|
komaz-ext 138.231.135.6 komaz alerts@crans.org Patte externe de notre routeur.
|
|
irts 138.231.135.5 komaz,komaz-ext alerts@crans.org Le routeur de l'ENS qui assure la liaison CRANS-ENS.
|
|
irts-ext 138.231.132.5 komaz,komaz-ext,irts alerts@crans.org Patte externe du routeur IRTS.
|
|
gateway.zrt 138.231.132.1 komaz,komaz-ext,irts,irts-ext alerts@crans.org Routeur de l'ENS
|
|
kwai 138.231.176.9 komaz,komaz-ext,irts,irts-ext,gateway.zrt alerts@crans.org Routeur de l'ENS
|
|
pioneer 138.231.176.1 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai alerts@crans.org Le routeur principal de lENS, Interface interne.
|
|
pioneer-ext 193.49.65.2 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer alerts@crans.org Le routeur principal de lENS, Interface externe.
|
|
RenaterCachan 193.49.65.1 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext alerts@crans.org Routeur RENATER
|
|
CachanCSSI1 193.51.181.186 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan alerts@crans.org Routeur RENATER
|
|
CachanCSSI2 193.51.181.185 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan,CachanCSSI1 alerts@crans.org Routeur RENATER
|
|
OrsayCSSI1 193.51.180.122 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan,CachanCSSI1,CachanCSSI2 alerts@crans.org Routeur RENATER
|
|
OrsayCSSI2 193.51.180.121 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan,CachanCSSI1,CachanCSSI2,OrsayCSSI1 alerts@crans.org Routeur RENATER
|
|
nriCSSI 193.51.179.41 komaz,komaz-ext,irts,irts-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan,CachanCSSI1,CachanCSSI2,OrsayCSSI1,OrsayCSSI2 alerts@crans.org Routeur RENATER
|
|
|
|
# serveurs du crans #
|
|
#####################
|
|
|
|
%%HTML: <TR> <TD class=table colSpan=3><p></TD></TR>
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="+1"><B>Serveurs :</font></b></TR>
|
|
|
|
%(serveurs)s
|
|
|
|
# switchs #
|
|
###########
|
|
|
|
%%HTML: <TR> <TD class=table colSpan=3><p></TD></TR>
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="+1"><B>Switchs :</font></b></TR>
|
|
|
|
%(switchs)s
|
|
|
|
# bornes wifi #
|
|
###############
|
|
|
|
%%HTML: <TR> <TD class=table colSpan=3><p></TD></TR>
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="+1"><B>Bornes wifi :</font></b></TR>
|
|
|
|
%(bornes)s
|
|
|
|
# Sites web et Services #
|
|
#########################
|
|
|
|
%%HTML: <TR> <TD class=table colSpan=3><p></TD></TR>
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="+1"><B>Sites web et Services HORS de l'ENS:</font></b></TR>
|
|
%%HTML: <TR><td colspan=3 class="table"><font size="2">(21:FTP ; 80:HTTP ; 119:news ; 5190:port du protocole ICQ)</TR>
|
|
|
|
Jussieu:21 195.83.118.1 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Le serveur <a href="ftp://ftp.lip6.fr">FTP</a> de Jussieu. (France)
|
|
Free:21 213.228.0.141 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Le serveur <a href="ftp://ftp.free.fr">FTP</a> de free. (France)
|
|
Voila:80 195.101.94.80 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Est-ce que <a href="http://www.voila.fr">Voila</a> fonctionne ? (France)
|
|
Yahoo!:80 66.94.230.39 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Est-ce que <a href="http://www.yahoo.com">Yahoo!</a> fonctionne ? (USA)
|
|
Altavista:80 216.155.200.155 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Est-ce que <a href="http://www.altavista.com">Altavista</a> fonctionne ? (USA)
|
|
"""
|
|
|
|
# service à redémarer
|
|
restart_cmd = ""
|
|
|
|
# FIN DE LA CONFIGURATION
|
|
|
|
def __str__ (self) :
|
|
return "autostatus"
|
|
|
|
def make_config (self, dico ) :
|
|
"""
|
|
Transforme le dico en suite lignes de configuration
|
|
"""
|
|
liste = dico.keys()
|
|
liste.sort()
|
|
append = ""
|
|
for i in liste :
|
|
append = append + " ".join( dico[i] ) + "\n"
|
|
return append.encode('iso-8859-15')
|
|
|
|
def _gen (self) :
|
|
|
|
# machines crans
|
|
machines = crans().machines()
|
|
|
|
# tri des machines par type
|
|
bornes = {}
|
|
switchs = {}
|
|
serveurs = {}
|
|
|
|
# tri des machines
|
|
for m in machines :
|
|
|
|
# machine exclue
|
|
if m.nom() in self.exclude :
|
|
continue
|
|
|
|
# les bornes
|
|
if m.canal() :
|
|
# C'est une borne
|
|
if m.info() :
|
|
# on regarde si c'est une borne de batiment
|
|
if ( m.info()[0][0:3] == "Au " ) and ( len(m.info()[0]) == 5 ) :
|
|
bornes[ "1-" + m.info()[0][4]+m.info()[0][3] ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , m.info()[0] ]
|
|
else :
|
|
bornes[ "2-" +m.info()[0] ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , m.info()[0] ]
|
|
else :
|
|
# on met les bornes non définies à la fin (ordre alphabétique)
|
|
bornes[ "3-" + m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , 'Inutilise' ]
|
|
|
|
# les switchs
|
|
elif 'bat' == m.nom()[0:3] or 'backbone.crans.org' == m.nom() :
|
|
|
|
# on convertit le bat# en bat#-0
|
|
if not "-" in m.nom().split(".")[0] :
|
|
index = m.nom().split(".")[0] + "-0"
|
|
else :
|
|
index = m.nom().split(".")[0]
|
|
|
|
# on ajoute au dictionnaire
|
|
if m.info() :
|
|
switchs[ index ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , m.info()[0] ]
|
|
else :
|
|
switchs[ index ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , 'Infos non disponibles' ]
|
|
|
|
# les serveurs
|
|
else :
|
|
if ".wifi.crans.org" in m.nom() :
|
|
nom = m.nom().split(".")[0] + ".wifi"
|
|
else :
|
|
nom = m.nom().split(".")[0]
|
|
if m.info() :
|
|
serveurs[ nom ] = [ nom , m.nom() , 'none' , 'nobody' , m.info()[0] ]
|
|
else :
|
|
serveurs[ nom ] = [ nom , m.nom() , 'none' , 'nobody' , 'Infos non disponibles' ]
|
|
|
|
# début du fichier
|
|
file = self._open_conf(self.CONFFILE, "#")
|
|
|
|
# génère le dictionnaire pour les modifications
|
|
dico = {}
|
|
dico['switchs'] = self.make_config(switchs)
|
|
dico['bornes'] = self.make_config(bornes)
|
|
dico['serveurs'] = self.make_config(serveurs)
|
|
|
|
# on écrit dans le fichier de configuration
|
|
file.write( self.matrice % dico )
|
|
|
|
# on ferme le fichier
|
|
file.close()
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
# base de données
|
|
tmp = autostatus()
|
|
|
|
# lancement du script
|
|
tmp.reconfigure()
|