This function shows how to create an object in eDirectory using Python and python-ldap. Parameters: handle - A connection handle as returned by __connect. dn - String representation of the dn for the object. attrs - An array of tuples, each of two strings, representing the attribute and value pairs that make up the object.
Note the sample below the function that demonstrates how the function is invoked.
import ldap
def __create( handle, dn, attrs ):
if not handle:
return False
handle.add_s( dn, attrs )
# Example - this code will create an object of the type posixAccount.
attrs = []
attrs.append( ("CN","cn=jdoe,o=users") )
attrs.append( ("Surname","Doe") )
attrs.append( ("objectClass","inetOrgPerson") )
attrs.append( ("objectClass","posixAccount") )
attrs.append( ("homeDirectory","/home/jdoe") )
attrs.append( ("gidNumber","1234") )
attrs.append( ("uidNumber","1234") )
attrs.append( ("uid","jdoe") )
attrs.append( ("Language","ENGLISH") )
attrs.append( ("passwordAllowChange","TRUE") )
handle = __connect( "localhost", "cn=admin,o=users", "password" )
if handle:
__create( handle, "cn=jdoe,o=users", attrs )
© 2008 Novell, Inc. All Rights Reserved.