Adding entries to ldap – PyLDAP

24 04 2007

In my previous post I explained on how we connect to ldap server and query the ldap server through python and ldap bindings. Today let us see how we add and delete entries from the ldap server using the same python and ldap bindings

Tthe add_entry function,

    def add_entry(self,machine_name):
    try:
    self.dn=’mc=’+machine_name+’,dc=udms,dc=com’
    self.modlist=[]
    self.modlist.append((‘objectClass’,['top','udms']))
    self.modlist.append((‘mc’,machine_name))
    self.modlist.append((‘ip’,’192.168.1.4′))self.ldms_var.add_s(self.dn,self.modlist)
    print “Machine “+machine_name+” added”
    except ldap.LDAPError,error_message:
    print error_message

Here we create a dictionary of the attributes and their values and pass to ldap’s add_s function along with the distinguished name (dn)

The delete_entry function,

    def delete_entry(self,machine_name):
    try:
    self.dn=’mc=’+machine_name+’,dc=udms,dc=com’
    self.ldms_var.delete_s(self.dn)
    print “Machine “+machine_name+” removed”
    except ldap.LDAPError,error_message:
    print error_message

Here we specify only the distinguished name (dn) to the ldap’s delete_s function

If you take the normal ldapadd and ldapdelete commands, you could easily figure out what we are doing with pyldap

ldapadd example,

ldapadd -x -W -D “cn=admin,dc=udms,dc=com” -f ldapuser.ldif

The ldapuser.ldif has all the attributes and dn specified.

ldapdelete example,

ldapdelete -x -W -D “cn=admin,dc=udms,dc=com” “mc=client2,dc=udms,dc=com”

Creative Commons License Creative Commons License

About these ads

Actions

Information

3 responses

23 10 2009
Coder61

As for the actress, I have no problem with her. ,

24 10 2009
Roy64

To create a democratically open project, youth have to find support for their present needs. ,

24 10 2009
His_wife56

Sometimes patients expect too much and are disappointed with the outcome or results. ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: