[Freeipa-users] What is the best way to make batch changes to the LDAP?

Joe Linoff jlinoff at tabula.com
Tue Jun 26 23:56:38 UTC 2012


Hi Everybody:

 

Here is a python approach that I am experimenting with based on reading
the source code. It seems to work but it is re-entrant? Does this make
sense? Is there a better way (like ldapmodify)?

 

#!/usr/bin/env python

#

# Emulate the ipa command line interface in a script so that 

# to batch some updates.

#

import sys

import shlex

from ipalib import api, cli

 

# ================================================================

# bootstrap

# ================================================================

def bootstrap():

    """

    Bootstrap the script.

    I hope that all of this stuff is re-entrant.

    Also, api is defined in __init__.py.

    """

    api.bootstrap_with_global_options(context='cli')

    for klass in cli.cli_plugins:

        api.register(klass)

    api.load_plugins()

    api.finalize()

    if not 'config_loaded' in api.env:

        raise NotConfiguredError()

 

# ================================================================

# cmd

# ================================================================

def cmd(cmd):

    """

    Execute an IPA command.

    The command is entered as a string. I use shlex.split

    to break it into an args list.

    @param cmd The command to execute (as a string).

    """

    print

    print '# %s' % ('='*64)

    print '# CMD: %s' % (cmd)

    print '# %s' % ('='*64)

   args=shlex.split(cmd)

    api.Backend.cli.run(args)

 

if __name__ == '__main__':

    bootstrap()

 

    # Some test calls.

    cmd('help')

    cmd('help user')

    cmd('help user-mod')

 

    # Update the fields.

    users=['bob', 'carol', 'ted', 'alice']

    mod='--street="123 Main Street" --city="Anytown" --state="AK"
--postalcode="12345"'

    for user in users:

        cmd('user-mod %s %s' % (user, mod))

 

Regards,

 

Joe

 

From: Joe Linoff 
Sent: Tuesday, June 26, 2012 3:04 PM
To: freeipa-users at redhat.com
Cc: Joe Linoff
Subject: What is the best way to make batch changes to the LDAP?

 

Hi Everybody:

 

I need to change the mailing address information for a group of
employees in the FreeIPA LDAP and would like to do it in a script. I
know that I can do it using "ipa user-mod" in a shell script but I was
wondering whether I could use python.

 

Does using python make sense? 

 

If so, are there any examples that I can look at? It seems that I could
import ipalib and go from there but I am not sure if there is a simple
interface for doing user modifications.

 

Any help would be greatly appreciated.

 

Thanks,

 

Joe

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/freeipa-users/attachments/20120626/6b35f07d/attachment.htm>


More information about the Freeipa-users mailing list