Python-ldap: LDAP client API for Python http://www.python-ldap.org/
1 import ldap
2 import ldap.modlist
3
4 con = ldap.open("127.0.0.1", 37225)
5 con.simple_bind('cn=Directory Manager', 'password')
6
7 #search
8 result = con.search_s('applicationName=SLF,nodeName=jambala',
9 ldap.SCOPE_SUBTREE,
10 '(objectClass=SLF-Imsi)')
11
12 print len(result)
13 for i in result:
14 print "DN:",i[0]
15 print "ATTRIB:", i[1]
16
17 dn = 'SLF-Imsi=159159160,SLF-ImsiContainerName=SLF-ImsiContainer, SLF-ProvisioningContainerName=SLF-ProvisioningContainer,applicationName=SLF,nodeName=jambala'
18
19 #add
20 attrs = {'SLF-DiaServers' : ['HSS2'], 'objectClass': ['SLF-Imsi', 'JIM-ManagedObject', 'top']}
21 ldif = ldap.modlist.addModlist(attrs)
22 con.add_s(dn, ldif)
23
24 #modify
25 oldattrs = {'SLF-DiaServers': []}
26 newattrs = {'SLF-DiaServers': ['HSS12']}
27 ldif = ldap.modlist.modifyModlist(oldattrs, newattrs)
28 con.modify_s(dn, ldif)
29
30 #delete
31 con.delete_s(dn)
32
33 con.unbind()