Skip to content
richm edited this page Sep 13, 2010 · 12 revisions

This is a collection of scripts (shell, perl, python) I use when testing 389 Directory Server.

Server Management Code

Directory Server management code is in dsadmin.py – this uses python-ldap to manage 389 Directory Server – it provides

  • code to manage suffixes and database backends, including chaining backends
  • code to manage replication – set up replicas, replication agreements, init replicas, check status, RUV, CSN
  • an Entry class – a high level interface to the lower level python-ldap functions and data structures
  • code to create new instances

 from dsadmin import DSAdmin, Entry
 host1 = "myhost"
 host2 = "otherhost"
 port = 389
 rootdn = "cn=Directory Manager"
 rootpw = "itsasecret"
 srv1 = DSAdmin(host1, port, rootdn, rootpw)
 replargs = {
	'suffix': "dc=example,dc=com",
	'bename': "userRoot",
	'binddn': "cn=replrepl,cn=config",
	'bindcn': "replrepl",
	'bindpw': "replrepl"
 #    'log'   : False
 }
 srv1.replicaSetupAll(replargs)
 srv2 = DSAdmin(host2, port, rootdn, rootpw)
 srv2.replicaSetupAll(replargs)

 agmt1 = srv1.setupAgreement(srv2, replargs)
 srv1.startReplication(agmt1)
 print "Replication status is ", srv1.getReplStatus(agmt1)
 agmt2 = srv2.setupAgreement(srv1, replargs)

 dn = "cn=test,dc=example,dc=com"
 ent = Entry(dn)
 ent.setValues("objectclass", "person")
 ent.setValues("sn", "Test")
 srv1.add(ent) # use try to catch exceptions
 # sleep for a second or two
 ent = srv2.getEntry(dn, ldap.SCOPE_BASE)
 print "entry was replicated", ent

There is a dirsyncctrl.py module that implements support for the Microsoft Active Directory DirSync Control, used with versions of python-ldap that support LDAP controls.

There are two Perl modules that provide similar functionality to dsadmin.py

  • NDSAdmin.pm – uses Mozilla::LDAP
  • NDSAdminNL.pm – uses Net::LDAP
Clone this wiki locally