Novell Home

Modify object attributes in eDirectory using LDAP and Python

From Developer Community

This code snippet shows a simple function that will modify attributes of an object using LDAP and python-ldap. Parameters: handle = a connection handle as returned by __connect dn = string representation of the DN of the object to be modified attrs = list of tuples that specify the changes to be made. Each tuple contains three values:

  • one of ldap.MOD_ADD, ldap.MOD_DELETE, or ldap.MOD_REPLACE depending on the action desired
  • string representing the schema attribute type (i.e. "instantMessagingID")
  • string or list of strings representing the value(s) to add, replace, or delete. If a delete, None will delete all values in a multivalued attribute

So, a valid value for attrs: [ (ldap.MOD_ADD, "instantMessagingID", "babybumkins") ].

See python-ldap documentation for more details.

Function

import ldap

def __modify( handle, dn, attrs ):
    if not handle:
        return False
    handle.modify_s( dn, attrs )

--Matt Ryan

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.