bh: utils/testing create_ldap_users.py,NONE,1.1

cvs at intevation.de cvs at intevation.de
Mon Apr 18 20:30:59 CEST 2005


Author: bh

Update of /kolabrepository/utils/testing
In directory doto:/tmp/cvs-serv6163

Added Files:
	create_ldap_users.py 
Log Message:
new script to create many ldap users in one go


--- NEW FILE: create_ldap_users.py ---
#!/bin/env python
"""Create some few kolab users in ldap"""

# requires the python-ldap module from
# http://python-ldap.sourceforge.net/
# on debian woody it's packaged as python-ldap

import ldap
import ldap.modlist
import getpass

# adjust these values to match your setup
# TODO: read some of these automatically from ldap
mail_domain = "example.com"
base_dn = "dc=example,dc=com"
admin_dn_part = "cn=some admin,cn=internal"
hostname = "kolabserver.example.com"

# number of users to create.  All users have email addresses of the form
# autotest%d at mail_domain where %d will be replaced by a number in
# range(num_users)
num_users = 10

def add_user():
    conn = ldap.open(hostname)
    pwd = getpass.getpass("ldap bind password:")
    conn.simple_bind_s(admin_dn_part + "," + base_dn, pwd)

    common_attrs = {
        'objectClass': ['top', 'inetOrgPerson', 'kolabInetOrgPerson'],
        'kolabHomeServer': ['neso.test.hq'],
        'kolabInvitationPolicy': ['ACT_MANUAL'],
        }

    users =  [("test%d" % n, "auto", "autotest%d" % n)
              for n in range(num_users)]
    for sn, givenName, mailuid in users:
        descr = common_attrs.copy()
        cn = givenName + " " + sn
        descr["cn"] = [cn]
        descr["givenName"] = [givenName]
        descr["sn"] = [sn]
        descr["mail"] = descr["uid"] = [mailuid + "@" + mail_domain]
        dn = "cn=" + cn + "," + base_dn
        print dn, descr
        print conn.add_s(dn, ldap.modlist.addModlist(descr))


add_user()





More information about the commits mailing list