[Freeipa-users] How can I change my password from a python script?
Joe Linoff
jlinoff at tabula.com
Thu Jun 28 01:34:19 UTC 2012
Hi Everybody:
I need to add a lot of users to an LDAP system for testing and I would
like to do it in batch mode. For my small tests have been doing
something like this:
#!/bin/bash
# Script to create a new user.
ipa user-add bigbob \
--email=bbob at BigBobsEmporium.com \
--first=Bob \
--last=Bigg \
--password \
--setattr=description='The sales guy.' <<-EOF
b1gB0bsTmpPwd
b1gB0bsTmpPwd
EOF
However, I am python guy and would like to use it instead. I am sure
that I can do a similar thing using pexpect in python. Probably
something like this:
# This code has not been tested. It is only for a thought experiment.
# Add a user and enter the password using pexpect.
cmd = "ipa user-add bigbob --email='bbob at BigBobsEmporium."
cmd += " --first=Bob --last=Bigg --password "
cmd += "--setattr=description='The sales guy.'"
rets = ['Password', 'Enter Password again to verify', pexpect.EOF,
pexpect.TIMEOUT]
c = pexpect.spawn(cmd,timeout=None)
i = c.expect(rets)
if i == 0: # Password
child.sendline('b1gB0bsTmpPwd')
i = c.expect(rets)
if i == 1: # Enter Password again to verify
child.sendline('b1gB0bsTmpPwd')
i = c.expect(rets)
if i == 2:
print 'SUCCESS'
else:
sys.exit('ERROR: something bad happened #1')
else:
sys.exit('ERROR: something bad happened #2')
else:
sys.exit('ERROR: something bad happened #3')
But I was wondering whether there was a better using the IPA API. Is
there a way for me to do that?
Any help or insights would be greatly appreciated.
Thanks,
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/freeipa-users/attachments/20120627/1af19e21/attachment.htm>
More information about the Freeipa-users
mailing list