Thanks for your answer, but I think that I don't explained my problem very clearly. Lets take this simple situation. I have two hosts: my client with apache+mod_python and my ipa server.<div><br></div><div>This is the apache configuration on client :</div>
<div><br></div><div><div>---------------------------------------------------------</div></div><div> <Files "test"><div> ## python conf </div>
<div> PythonPath "['/usr/lib/python2.6/site-packages/webservices']+sys.path"</div><div> SetHandler python-program</div><div> PythonHandler my_script</div><div> PythonDebug on</div><div></Files></div>
<div><div>---------------------------------------------------------</div></div><div><br></div><div>and this the code of `my_script`</div><div><br></div><div>---------------------------------------------------------</div>
<div>
from mod_python import apache</div><div><br></div><div>def handler(req):</div><div> req.content_type = "text/plain"</div><div> req.send_http_header()</div><div> from ipalib import api</div><div> # I am on the client host => mode server is False</div>
<div> # I also tested this with api.bootstrap(context='example', in_server=False) but it doesn't work too</div><div> api.bootstrap_with_global_options(context='example')</div><div> api.finalize()</div>
<div> api.Backend.xmlclient.connect()</div><div> res = api.Command.user_show(user_name)</div><div> req.write(str(res))</div><div><br></div><div> return apache.OK</div><div><div>---------------------------------------------------------</div>
</div><div><br></div><div>when I access to <a href="http://client.domain.org/test">client.domain.org/test</a> on my browser I get this error :</div><div><br></div><div><div>---------------------------------------------------------</div>
</div><div><div>MOD_PYTHON ERROR</div><div><br></div><div>ProcessId: 12393</div><div>Interpreter: '<a href="http://client.domain.org">client.domain.org</a>'</div><div><br></div><div>ServerName: '<a href="http://client.domain.org">client.domain.org</a>'</div>
<div>DocumentRoot: '/var/www/html'</div><div><br></div><div>URI: '/test'</div><div>Location: None</div><div>Directory: None</div><div>Filename: '/var/www/html/test'</div>
<div>PathInfo: ''</div><div><br></div><div>Phase: 'PythonHandler'</div><div>Handler: 'my_script'</div><div><br></div><div>Traceback (most recent call last):</div><div><br></div>
<div> File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch</div><div> default=default_handler, arg=req, silent=hlist.silent)</div><div><br></div><div> File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1229, in _process_target</div>
<div> result = _execute_target(config, req, object, arg)</div><div><br></div><div> File "/usr/lib/python2.6/site-packages/mod_python/importer.py", line 1128, in _execute_target</div><div> result = object(arg)</div>
<div><br></div><div> File "/usr/lib/python2.6/site-packages/webservices/my_script.py", line 7, in handler</div><div> api.bootstrap(context='example', in_server=False)</div><div><br></div><div> File "/usr/lib/python2.6/site-packages/ipalib/plugable.py", line 380, in bootstrap</div>
<div> self.__doing('bootstrap')</div><div><br></div><div> File "/usr/lib/python2.6/site-packages/ipalib/plugable.py", line 365, in __doing</div><div> '%s.%s() already called' % (self.__class__.__name__, name)</div>
<div><br></div><div>StandardError: API.bootstrap() already called</div></div><div><div>---------------------------------------------------------</div></div><div><br></div><div>I don't know where API.bootstrap() was called.</div>
<div><br></div><div>Thanks,</div><div><br></div><div class="gmail_quote">2010/4/20 Jason Gerard DeRose <span dir="ltr"><<a href="mailto:jderose@redhat.com">jderose@redhat.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, 2010-04-20 at 13:03 +0200, ALAHYANE Rachid wrote:<br>
> Hi,<br>
><br>
><br>
</div><div><div></div><div class="h5">> Now I have another error. When I use the code<br>
> of doc/examples/python-api.py inside my server XML-RPC (not the ipa<br>
> server) that configured like this :<br>
><br>
><br>
> == Server ==<br>
> --------- httpd conf ------------<br>
> <Files "xmlrpc"><br>
> ## python conf<br>
><br>
><br>
> # ....<br>
> SetHandler python-program<br>
> PythonHandler xmlrpchandler<br>
> PythonDebug on<br>
> </Files><br>
> ------------------------------------<br>
><br>
><br>
> the handler xmlrpchandler calls the following method when the client<br>
> requests for the remote method getUserInfos().<br>
><br>
><br>
> --------- account.py ------------<br>
> def getUserInfos(user_name, env=None):<br>
><br>
><br>
> from ipalib import api<br>
><br>
><br>
> api.bootstrap_with_global_options(context='webservices')<br>
> api.finalize()<br>
> api.Backend.xmlclient.connect()<br>
> return api.Command.user_show(user_name)<br>
> ------------------------------------<br>
><br>
><br>
><br>
><br>
> == Client ==<br>
> Now when I call this method from my client, I get this exception :<br>
><br>
><br>
> ------------------------------------<br>
> <Fault 2: "account.getUserInfos: <type 'exceptions.StandardError'>:<br>
> API.bootstrap() already called"><br>
> ------------------------------------<br>
><br>
><br>
> I don't know why it does not work, any ideas ??<br>
><br>
<br>
</div></div>Initializing ipalib is a somewhat expensive operation, so we only<br>
initialize it once when the process starts. If you're implementing a<br>
new XML-RPC server that calls ipalib, you will need to slightly modify<br>
the code in the python-api.py example, which I'll explain.<br>
<br>
ipalib has 2 modes of operation: client and server. In client mode,<br>
only plugins in ipalib/plugins/ are loaded. In server mode, plugins in<br>
ipaserver/plugins/ are also loaded.<br>
<br>
In a nutshell, client mode will do some sanity checks and the forward<br>
the call to the server. In server mode, the same sanity checks are<br>
performed, and then the command is executed, which usually means<br>
creating/modifying LDAP entries.<br>
<br>
So assuming you want to initialize ipalib in server mode (sounds like<br>
you do), you will need to do something like this (when the process<br>
starts):<br>
<br>
from ipalib import api<br>
api.bootstrap(context='example', in_server=True)<br>
api.finalize()<br>
<br>
Note the `in_server=True` that I added. Then in your handler, you will<br>
need to create a context for the request, something like this:<br>
<div class="im"><br>
def getUserInfos(user_name, env=None):<br>
</div> # Where are you getting Kerberos credentials?<br>
api.Backend.ldap2.connect(<br>
ccache=api.Backend.krb.default_ccname()<br>
<div class="im"> )<br>
return api.Command.user_show(user_name)<br>
<br>
</div>So the recipe is 1) initialize ipalib once at startup, and 2) create a<br>
context (LDAP connection) at each request. To see how we do this is our<br>
RPC server, look at the ipaserver/rpcserver.py file.<br>
<br>
Hope that helps. I'm glad to see someone wanting to use the Python<br>
API. ;)<br>
<div><div></div><div class="h5"><br>
> Thanks,<br>
><br>
><br>
> 2010/4/19 ALAHYANE Rachid <<a href="mailto:afkkir@gmail.com">afkkir@gmail.com</a>><br>
> Thank you for your answer, it works !<br>
><br>
> 2010/4/19 Jason Gerard DeRose <<a href="mailto:jderose@redhat.com">jderose@redhat.com</a>><br>
><br>
><br>
> On Mon, 2010-04-19 at 16:22 +0200, ALAHYANE Rachid<br>
> wrote:<br>
> > Hi,<br>
> ><br>
> ><br>
> > Using F12 with the alpha version of ipa, I want to<br>
> know if there is<br>
> > some ways to call implemented methods like<br>
> user_show() with my own<br>
> > script python. My goal is to call these methods with<br>
> a client xml-rpc<br>
> > that I will to developpe later.<br>
> ><br>
> ><br>
> > On my client, I tried this but it does not work :(<br>
><br>
><br>
> It needs more documentation, but see<br>
> doc/examples/python-api.py<br>
><br>
> Let me know if that doesn't work or if you get stuck.<br>
> You will need to<br>
> do a kinit first.<br>
><br>
><br>
> ><br>
> ----------------------------------------------------------------------------<br>
> > >>> from ipalib import api<br>
> > >>> api.bootstrap_with_global_options()<br>
> > (<Values at 0xb74f556c: {'debug': None, 'conf':<br>
> None, 'env': None,<br>
> > 'verbose': None}>, [])<br>
> > >>> api.load_plugins()<br>
> > >>> api.finalize()<br>
> > >>> api.Method.user_show.__doc__<br>
> > '\n Display user.\n '<br>
> > >>> api.Method.user_show(u'raca')<br>
> > Traceback (most recent call last):<br>
> > File "<stdin>", line 1, in <module><br>
> > File<br>
> "/usr/lib/python2.6/site-packages/ipalib/frontend.py",<br>
> line<br>
> > 398, in __call__<br>
> > ret = self.run(*args, **options)<br>
> > File<br>
> "/usr/lib/python2.6/site-packages/ipalib/frontend.py",<br>
> line<br>
> > 667, in run<br>
> > return self.forward(*args, **options)<br>
> > File<br>
> "/usr/lib/python2.6/site-packages/ipalib/frontend.py",<br>
> line<br>
> > 688, in forward<br>
> > return self.Backend.xmlclient.forward(<a href="http://self.name" target="_blank">self.name</a>,<br>
> *args, **kw)<br>
> > File<br>
> "/usr/lib/python2.6/site-packages/ipalib/rpc.py", line<br>
> 403, in<br>
> > forward<br>
> > command = getattr(self.conn, name)<br>
> > File<br>
> "/usr/lib/python2.6/site-packages/ipalib/backend.py",<br>
> line 96,<br>
> > in __get_conn<br>
> > <a href="http://self.id" target="_blank">self.id</a>, threading.currentThread().getName())<br>
> > AttributeError: no context.xmlclient in thread<br>
> 'MainThread'<br>
> ><br>
> ><br>
> ><br>
> ----------------------------------------------------------------------------<br>
> ><br>
> ><br>
> > Have you any idea ? or some pertinent docs<br>
> ><br>
> ><br>
> > Sorry for my bad English :)<br>
> ><br>
> ><br>
> > --<br>
> > Meilleures salutations / Best Regards<br>
> ><br>
> > Rachid ALAHYANE<br>
> ><br>
> ><br>
><br>
> > _______________________________________________<br>
> > Freeipa-users mailing list<br>
> > <a href="mailto:Freeipa-users@redhat.com">Freeipa-users@redhat.com</a><br>
> ><br>
> <a href="https://www.redhat.com/mailman/listinfo/freeipa-users" target="_blank">https://www.redhat.com/mailman/listinfo/freeipa-users</a><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> Meilleures salutations / Best Regards<br>
><br>
> Rachid ALAHYANE<br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> Meilleures salutations / Best Regards<br>
><br>
> Rachid ALAHYANE<br>
><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Meilleures salutations / Best Regards<br><br>Rachid ALAHYANE<br><br>
</div>