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”







As for the actress, I have no problem with her. ,
To create a democratically open project, youth have to find support for their present needs. ,
Sometimes patients expect too much and are disappointed with the outcome or results. ,