Merge branch 'master' of https://gitlab.adm.crans.org/nounous/scripts
Pull de /usr/scripts et maj du depot
This commit is contained in:
commit
23c9df55eb
1 changed files with 22 additions and 28 deletions
|
@ -11,6 +11,8 @@ Licence : GPLv2
|
||||||
import sys
|
import sys
|
||||||
from config import NETs
|
from config import NETs
|
||||||
from iptools import AddrInNet
|
from iptools import AddrInNet
|
||||||
|
import netaddr
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from dialog import Dialog
|
from dialog import Dialog
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -18,14 +20,6 @@ except ImportError:
|
||||||
|
|
||||||
repertoire = '/usr/scripts/var/numeros_disponibles/'
|
repertoire = '/usr/scripts/var/numeros_disponibles/'
|
||||||
|
|
||||||
"""
|
|
||||||
Un petit hack de rien du tout pour s'assurer qu'on n'attribue
|
|
||||||
pas ces adresses. Certains services risquent de continuer
|
|
||||||
d'essayer de se connecter a ces adresses
|
|
||||||
"""
|
|
||||||
ancien_vlan_adm = ['10.231.136.0/24']
|
|
||||||
|
|
||||||
|
|
||||||
def lister_ip_dispo(plage):
|
def lister_ip_dispo(plage):
|
||||||
f = open(repertoire + 'ip_' + plage)
|
f = open(repertoire + 'ip_' + plage)
|
||||||
lignes = f.readlines()
|
lignes = f.readlines()
|
||||||
|
@ -48,25 +42,14 @@ def update_ip(plage, occupees):
|
||||||
net = NETs[plage]
|
net = NETs[plage]
|
||||||
pool_ip = [] # Pool d'IP à tester
|
pool_ip = [] # Pool d'IP à tester
|
||||||
for ne in net:
|
for ne in net:
|
||||||
ip = ne.split('/')[0]
|
ne = netaddr.IPNetwork(ne)
|
||||||
ip = ip.split('.')
|
for ip in ne:
|
||||||
n = []
|
# avoid .255 and .0 (even for non-/24 nets)
|
||||||
for i in ip:
|
if (ip.value & 255) in [0,255]:
|
||||||
n.append(int(i))
|
continue
|
||||||
while 1:
|
pool_ip.append(str(ip))
|
||||||
if n[3] < 254:
|
|
||||||
n[3] += 1
|
|
||||||
else:
|
|
||||||
n[2] += 1
|
|
||||||
n[3] = 1
|
|
||||||
if n[2] == 255: break
|
|
||||||
ip = "%d.%d.%d.%d" % tuple(n)
|
|
||||||
if not AddrInNet(ip, ne):
|
|
||||||
# On est allé trop loin
|
|
||||||
break
|
|
||||||
pool_ip.append(ip)
|
|
||||||
|
|
||||||
resultat = ''.join('%s\n' % ip for ip in pool_ip if ip not in occupees and not AddrInNet(ip, ancien_vlan_adm))
|
resultat = ''.join('%s\n' % ip for ip in pool_ip if ip not in occupees)
|
||||||
|
|
||||||
f = open(repertoire + 'ip_' + plage,'w')
|
f = open(repertoire + 'ip_' + plage,'w')
|
||||||
f.write(resultat)
|
f.write(resultat)
|
||||||
|
@ -78,6 +61,17 @@ def update_ip_fixe(occupees):
|
||||||
def update_ip_wifi_adh(occupees):
|
def update_ip_wifi_adh(occupees):
|
||||||
update_ip('wifi-adh','ip_wifi-adh', occupees)
|
update_ip('wifi-adh','ip_wifi-adh', occupees)
|
||||||
|
|
||||||
|
TO_COMPUTE = [
|
||||||
|
'wifi',
|
||||||
|
'wifi-adh',
|
||||||
|
'serveurs',
|
||||||
|
'adherents',
|
||||||
|
'bornes',
|
||||||
|
'adm',
|
||||||
|
'personnel-ens',
|
||||||
|
'fil',
|
||||||
|
]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if "--cron" in sys.argv:
|
if "--cron" in sys.argv:
|
||||||
cron = True
|
cron = True
|
||||||
|
@ -88,9 +82,9 @@ if __name__ == "__main__":
|
||||||
dlg.gauge_start(text="Recherche des machines...", backtitle="numeros_disponibles")
|
dlg.gauge_start(text="Recherche des machines...", backtitle="numeros_disponibles")
|
||||||
ip_occupees = lister_ip_utilisees()
|
ip_occupees = lister_ip_utilisees()
|
||||||
done = 1
|
done = 1
|
||||||
for net in NETs.keys():
|
for net in TO_COMPUTE:
|
||||||
if not cron:
|
if not cron:
|
||||||
dlg.gauge_update(int(done*100/(len(NETs)+1)), text="IP libres dans %s" % net, update_text=True)
|
dlg.gauge_update(int(done*100/(len(TO_COMPUTE)+1)), text="IP libres dans %s" % net, update_text=True)
|
||||||
update_ip(net, ip_occupees)
|
update_ip(net, ip_occupees)
|
||||||
done += 1
|
done += 1
|
||||||
if not cron:
|
if not cron:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue