* Corrections pour que les rid non désirés ne soient pas pris.
This commit is contained in:
parent
18571ae112
commit
6b55396794
2 changed files with 40 additions and 13 deletions
46
attributs.py
46
attributs.py
|
@ -33,13 +33,16 @@
|
||||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
import re, sys, netaddr, time
|
import re
|
||||||
|
import sys
|
||||||
|
import netaddr
|
||||||
|
import time
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
from crans_utils import format_tel, format_mac, mailexist, validate_name, ip4_of_rid, ip6_of_mac
|
from crans_utils import format_tel, format_mac, mailexist, validate_name, ip4_of_rid, ip6_of_mac
|
||||||
|
|
||||||
sys.path.append("/usr/scripts/gestion")
|
sys.path.append("/usr/scripts/gestion")
|
||||||
import config, annuaires_pg
|
import config
|
||||||
from ridtools import Rid
|
import annuaires_pg
|
||||||
|
|
||||||
### Les droits
|
### Les droits
|
||||||
# en cas de typo, l'appel d'une variable plante, on préfèrera donc les utiliser en lieu et place
|
# en cas de typo, l'appel d'une variable plante, on préfèrera donc les utiliser en lieu et place
|
||||||
|
@ -207,6 +210,9 @@ class aid(intAttr):
|
||||||
|
|
||||||
can_view = [nounou, apprenti, 'Cableurs']
|
can_view = [nounou, apprenti, 'Cableurs']
|
||||||
|
|
||||||
|
def parse_value(self, val, ldif):
|
||||||
|
self.value = int(val)
|
||||||
|
|
||||||
class uid(Attr):
|
class uid(Attr):
|
||||||
singlevalue = True
|
singlevalue = True
|
||||||
option = False
|
option = False
|
||||||
|
@ -468,8 +474,7 @@ class ip6HostNumber(Attr):
|
||||||
can_modify = [nounou]
|
can_modify = [nounou]
|
||||||
|
|
||||||
def parse_value(self, ip, ldif):
|
def parse_value(self, ip, ldif):
|
||||||
if ip == '<automatique>':
|
ip = ip6_of_mac(ldif['macAddress'][0], ldif['rid'][0])
|
||||||
ip = ip6_of_mac(ldif['macAddress'][0], ldif['rid'][0])
|
|
||||||
self.value = netaddr.ip.IPAddress(ip)
|
self.value = netaddr.ip.IPAddress(ip)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
@ -479,28 +484,44 @@ class mid(Attr):
|
||||||
singlevalue = True
|
singlevalue = True
|
||||||
optional = False
|
optional = False
|
||||||
unique = True
|
unique = True
|
||||||
legend = "Identifiant de machine"
|
legend = u"Identifiant de machine"
|
||||||
category = 'id'
|
category = 'id'
|
||||||
|
|
||||||
def parse_value(self, mid, ldif):
|
def parse_value(self, mid, ldif):
|
||||||
self.value = mid
|
self.value = int(mid)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(int(self.value))
|
return unicode(self.value)
|
||||||
|
|
||||||
class rid(Attr):
|
class rid(Attr):
|
||||||
singlevalue = True
|
singlevalue = True
|
||||||
optional = False
|
optional = False
|
||||||
unique = True
|
unique = True
|
||||||
legend = "Identifiant réseau de machine"
|
legend = u"Identifiant réseau de machine"
|
||||||
category = 'id'
|
category = 'id'
|
||||||
can_modify = [nounou]
|
can_modify = [nounou]
|
||||||
|
|
||||||
def parse_value(self, rid, ldif):
|
def parse_value(self, rid, ldif):
|
||||||
self.value = Rid(rid = int(rid))
|
rid = int(rid)
|
||||||
|
|
||||||
|
# On veut éviter les rid qui recoupent les ipv4 finissant par
|
||||||
|
# .0 ou .255
|
||||||
|
plages = [xrange(rid[a][0], rid[a][1]+1) for a in rid.keys() if 'v6' not in a]
|
||||||
|
|
||||||
|
for plage in plages:
|
||||||
|
if rid in plage:
|
||||||
|
if rid % 256 == 0 or rid % 256 == 255:
|
||||||
|
rid = -1
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.value = rid
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(int(self.value))
|
return unicode(self.value)
|
||||||
|
|
||||||
class ipsec(Attr):
|
class ipsec(Attr):
|
||||||
singlevalue = False
|
singlevalue = False
|
||||||
|
@ -587,6 +608,9 @@ class cid(intAttr):
|
||||||
unique = True
|
unique = True
|
||||||
legend = u"Identifiant du club"
|
legend = u"Identifiant du club"
|
||||||
category = 'id'
|
category = 'id'
|
||||||
|
|
||||||
|
def parse_value(self, val, ldif):
|
||||||
|
self.value = int(val)
|
||||||
|
|
||||||
class responsable(Attr):
|
class responsable(Attr):
|
||||||
singlevalue = True
|
singlevalue = True
|
||||||
|
|
|
@ -60,7 +60,6 @@ import config
|
||||||
import crans_utils
|
import crans_utils
|
||||||
from attributs import *
|
from attributs import *
|
||||||
from ldap_locks import CransLock
|
from ldap_locks import CransLock
|
||||||
import ridtools
|
|
||||||
|
|
||||||
uri = 'ldap://ldap.adm.crans.org/'
|
uri = 'ldap://ldap.adm.crans.org/'
|
||||||
base_dn = 'ou=data,dc=crans,dc=org'
|
base_dn = 'ou=data,dc=crans,dc=org'
|
||||||
|
@ -326,7 +325,11 @@ class lc_ldap(ldap.ldapobject.LDAPObject):
|
||||||
if i in nonfree:
|
if i in nonfree:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
my_id = attrify(i, attr, self, True)
|
||||||
|
if my_id.value != i:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
raise EnvironmentError('Aucun %s libre dans la plage [%d, %d]' %
|
raise EnvironmentError('Aucun %s libre dans la plage [%d, %d]' %
|
||||||
(attr, plage[0], i))
|
(attr, plage[0], i))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue