MID/RID : prise en compte partielle ici.
Les scripts en prod ne devraient pas souffrir de la modif.
This commit is contained in:
parent
3e458b2dec
commit
5a1a445411
3 changed files with 24 additions and 9 deletions
29
attributs.py
29
attributs.py
|
@ -39,7 +39,7 @@ from crans_utils import format_tel, format_mac, mailexist, validate_name
|
|||
|
||||
sys.path.append("/usr/scripts/gestion")
|
||||
import config, annuaires_pg
|
||||
from midtools import Mid
|
||||
from ridtools import Rid
|
||||
|
||||
### Les droits
|
||||
# en cas de typo, l'appel d'une variable plante, on préfèrera donc les utiliser en lieu et place
|
||||
|
@ -286,9 +286,9 @@ class mail(Attr):
|
|||
raise ValueError("Mail déjà existant", [r.dn for r in res])
|
||||
|
||||
def parse_value(self, mail, ldif):
|
||||
if not re.match('^[A-Za-z][-_.0-9A-Za-z]+@([A-Za-z0-9]{2}[A-Za-z0-9-_]*[.])+[a-z]{2,6}$', val):
|
||||
raise ValueError("Adresse mail invalide (%s)" % val)
|
||||
self.value = val
|
||||
if not re.match('^[-_.0-9A-Za-z]+@([A-Za-z0-9]{1}[A-Za-z0-9-_]+[.])+[a-z]{2,6}$', mail):
|
||||
raise ValueError("Adresse mail invalide (%s)" % ldif)
|
||||
self.value = mail
|
||||
|
||||
|
||||
class canonicalAlias(mail):
|
||||
|
@ -301,7 +301,7 @@ class canonicalAlias(mail):
|
|||
def parse_value(self, val, ldif):
|
||||
val = u".".join([ a.capitalize() for a in val.split(u'.', 1) ])
|
||||
val = u"-".join([ a.capitalize() for a in val.split(u'-', 1) ])
|
||||
if not re.match('^[A-Za-z][-_.0-9A-Za-z]+@([A-Za-z0-9]{2}[A-Za-z0-9-_]*[.])+[a-z]{2,6}$', val):
|
||||
if not re.match('^[-_.0-9A-Za-z]+@([A-Za-z0-9]{1}[A-Za-z0-9-_]+[.])+[a-z]{2,6}$', val):
|
||||
raise ValueError("Alias mail invalide (%s)" % val)
|
||||
self.value = val
|
||||
|
||||
|
@ -315,7 +315,7 @@ class mailAlias(mail):
|
|||
|
||||
def parse_value(self, val, ldif):
|
||||
val = val.lower()
|
||||
if not re.match('^[A-Za-z][-_.0-9A-Za-z]+@([A-Za-z0-9]{2}[A-Za-z0-9-_]*[.])+[a-z]{2,6}$', val):
|
||||
if not re.match('^[-_.0-9A-Za-z]+@([A-Za-z0-9]{2}[A-Za-z0-9-_]+[.])+[a-z]{2,6}$', val):
|
||||
raise ValueError("Alias mail invalide (%r)" % val)
|
||||
self.value = val
|
||||
|
||||
|
@ -450,7 +450,7 @@ class ipHostNumber(Attr):
|
|||
|
||||
def parse_value(self, ip, ldif):
|
||||
if ip == '<automatique>':
|
||||
ip = Mid(mid= ldif['mid'][0]).ipv4()
|
||||
ip = Rid(rid= ldif['rid'][0]).ipv4()
|
||||
self.value = netaddr.ip.IPAddress(ip)
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -465,11 +465,23 @@ class mid(Attr):
|
|||
category = 'id'
|
||||
|
||||
def parse_value(self, mid, ldif):
|
||||
self.value = Mid(mid = int(mid))
|
||||
self.value = mid
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(int(self.value))
|
||||
|
||||
class rid(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
unique = True
|
||||
legend = "Identifiant réseau de machine"
|
||||
category = 'id'
|
||||
|
||||
def parse_value(self, rid, ldif):
|
||||
self.value = Rid(rid = int(rid))
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(int(self.value))
|
||||
|
||||
class ipsec(Attr):
|
||||
singlevalue = False
|
||||
|
@ -781,6 +793,7 @@ CRANS_ATTRIBUTES= {
|
|||
'solde' : solde,
|
||||
'gpgFingerprint' : gpgFingerprint,
|
||||
'mid' : mid,
|
||||
'rid' : rid,
|
||||
'host' : host,
|
||||
'sshFingerprint' : sshFingerprint,
|
||||
'macAddress': macAddress,
|
||||
|
|
|
@ -77,6 +77,8 @@ def ip6_of_mac(mac, mid):
|
|||
else:
|
||||
raise ValueError("Mid dans aucune plage: %d" % mid)
|
||||
|
||||
print net
|
||||
|
||||
# En théorie, format_mac est inutile, car on ne devrait avoir
|
||||
# que des mac formatées.
|
||||
mac = format_mac(mac).replace(':', '')
|
||||
|
|
|
@ -48,7 +48,7 @@ sys.path.append('/usr/scripts/gestion')
|
|||
import config, crans_utils
|
||||
from attributs import attrify, blacklist
|
||||
from ldap_locks import CransLock
|
||||
import midtools
|
||||
import ridtools
|
||||
|
||||
uri = 'ldap://ldap.adm.crans.org/'
|
||||
base_dn = 'ou=data,dc=crans,dc=org'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue