I am trying to work with create_api for replica promotion code. After I change the default.conf file configuration from client to master it seem I am not getting ldap2 initialized anymore:
>>> from ipalib import api >>> api.bootstrap(context='installer') >>> api.finalize() >>> api.Backend.ldap2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NameSpace' object has no attribute 'ldap2'
shuld work with in_server=True in api.bootstrap()
in_server=True works when instantiating the base api, but fails with create_api() in this situation which is what I find myself in:
>>> from ipalib import api >>> api.finalize() >>> from ipalib import create_api >>> napi = create_api() >>> napi.bootstrap(context='installer', in_server=True) >>> napi.finalize() >>> napi.Backend.ldap2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NameSpace' object has no attribute 'ldap2'
The problem seems to be that {{{create_api()}}} call sets mode to 'dummy' by default. This means that no plugins are loaded:
myapi = create_api() >>> myapi.bootstrap(context='installer', in_server=True) >>> myapi.finalize() >>> myapi.Backend.ldap2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NameSpace' object has no attribute 'ldap2' >>> myapi.Backend NameSpace(<0 members>, sort=True) >>> myapi.Command NameSpace(<0 members>, sort=True)
As a workaround, call {{{create_api(mode=None)}}} (as can be seen in ipalib/__init__.py on line 935), which populates all the plugins properly:
ipalib/__init__.py
myapi = create_api(mode=None) >>> myapi.bootstrap(context='installer', in_server=True) >>> myapi.finalize() >>> myapi.Backend NameSpace(<8 members>, sort=True) >>> myapi.Backend.ldap2 ipaserver.plugins.ldap2.ldap2()
Thanks a lot Martin, this workaround works. Do we think this is the standard way all this machinery should work ? If so feel free to close the bug. I would love to have ldap2 working also when in_server is not set, so that I can connect to the ipa master from a client for example.
The correct procedure with reasonings should be documented in source code.
FreeIPA 4.2.1 was released, moving to 4.2.x.
Metadata Update from @simo: - Issue assigned to someone - Issue set to the milestone: FreeIPA 4.5 backlog
Login to comment on this ticket.