#! /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: Routeurs, dans l'ordre où ils sont entre le crans et l'extérieur : 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:

%%HTML: Serveurs : %(serveurs)s # switchs # ########### %%HTML:

%%HTML: Switchs : %(switchs)s # bornes wifi # ############### %%HTML:

%%HTML: Bornes wifi : %(bornes)s # Sites web et Services # ######################### %%HTML:

%%HTML: Sites web et Services HORS de l'ENS: %%HTML: (21:FTP ; 80:HTTP ; 119:news ; 5190:port du protocole ICQ) Jussieu:21 195.83.118.1 irts,irts-ext,komaz,komaz-ext,gateway.zrt,kwai,pioneer,pioneer-ext,RenaterCachan nobody Le serveur FTP 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 FTP 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 Voila 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 Yahoo! 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 Altavista 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 m.info() : serveurs[ m.nom() ] = [ m.nom().split(".")[0] , m.nom() , 'none' , 'nobody' , m.info()[0] ] else : serveurs[ m.nom() ] = [ m.nom().split(".")[0] , 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()