Nettement plus rapide !
darcs-hash:20070521174313-c992d-0208c36726b291fe3ab1cc85526bbd4b61c82368.gz
This commit is contained in:
parent
5a7d58f5a7
commit
961663c979
1 changed files with 21 additions and 11 deletions
|
@ -8,7 +8,7 @@ Copyright (C) Alexandre Bos, largement pompe sur ldap_crans.py
|
|||
Licence : GPLv2
|
||||
"""
|
||||
|
||||
from ldap_crans import crans_ldap
|
||||
|
||||
from config import NETs
|
||||
from iptools import AddrInNet
|
||||
|
||||
|
@ -17,9 +17,19 @@ noms_fichiers = {
|
|||
'ip_wifi-adh' : '/usr/scripts/var/numeros_disponibles/ip_wifi-adh'
|
||||
}
|
||||
|
||||
db = crans_ldap()
|
||||
|
||||
def _update_ip(plage, fichier):
|
||||
|
||||
def lister_ip_utilisees():
|
||||
liste = []
|
||||
from ldap_crans import crans_ldap
|
||||
db = crans_ldap()
|
||||
r = db.search('mid=*')
|
||||
machines = r['machineFixe'] + r['machineWifi'] + r['machineCrans']
|
||||
for m in machines:
|
||||
liste.append(m.ip())
|
||||
return liste
|
||||
|
||||
def _update_ip(plage, fichier, occupees):
|
||||
net = NETs[plage]
|
||||
pool_ip = [] # Pool d'IP à tester
|
||||
for ne in net:
|
||||
|
@ -44,20 +54,20 @@ def _update_ip(plage, fichier):
|
|||
resultat = ''
|
||||
|
||||
for ip in pool_ip:
|
||||
if not db.exist('ipHostNumber=%s' % ip):
|
||||
if ip not in occupees :
|
||||
resultat += '%s\n' % ip
|
||||
print '%s\n' % ip
|
||||
|
||||
f = open(noms_fichiers[fichier],'w')
|
||||
f.write(resultat)
|
||||
f.close
|
||||
|
||||
def update_ip_fixe():
|
||||
_update_ip('fil', 'ip_fil')
|
||||
def update_ip_fixe(occupees):
|
||||
_update_ip('fil', 'ip_fil', occupees)
|
||||
|
||||
def update_ip_wifi_adh():
|
||||
_update_ip('wifi-adh','ip_wifi-adh')
|
||||
def update_ip_wifi_adh(occupees):
|
||||
_update_ip('wifi-adh','ip_wifi-adh', occupees)
|
||||
|
||||
if __name__ == "__main__":
|
||||
update_ip_fixe()
|
||||
update_ip_wifi_adh()
|
||||
occupees = lister_ip_utilisees()
|
||||
update_ip_fixe(occupees)
|
||||
update_ip_wifi_adh(occupees)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue