Passage de stats_ip à lc_ldap

This commit is contained in:
Gabriel Detraz 2015-08-18 01:25:54 +02:00
parent 8f3f9c13da
commit dd32a30814

View file

@ -1,21 +1,22 @@
#! /usr/bin/env python #!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap from lc_ldap import shortcuts
from config import NETs from config import NETs
from iptools import AddrInNet from iptools import AddrInNet
ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ] ldap = shortcuts.lc_ldap_readonly()
ips = [ unicode(x['ipHostNumber'][0]) for x in ldap.search(u'(ipHostNumber=*)',sizelimit=10000)]
for n in NETs: for n in NETs:
nb_total = 0 nb_total = 0
for net in NETs[n]: for net in NETs[n]:
nb_total += 2 ** ( 32 - int( net.split('/')[1] ) ) nb_total += 2 ** ( 32 - int( net.split('/')[1] ) )
nb_occupe = len( [ ip for ip in ips if AddrInNet( ip, NETs[n] ) ] ) nb_occupe = len( [ ip for ip in ips if AddrInNet( ip, NETs[n] ) ] )
print '%12s %2s%% (%s/%s)' % (n, 100*nb_occupe/nb_total, nb_occupe, nb_total) print '%12s %2s%% (%s/%s)' % (n, 100*nb_occupe/nb_total, nb_occupe, nb_total)