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