Hello Alexander.

Thank you for your answer.
Do you know if I will have any problem with the certificate to connect to the server ?
Generally there is a ca.crt in /etc/ipa/ca.crt, does it need to be included in the virtual environment also ?

Best regards.

Lune

Le ven. 23 août 2019 à 15:06, Alexander Bokovoy <abokovoy@redhat.com> a écrit :
On pe, 23 elo 2019, lune voo via FreeIPA-users wrote:
>Hello everyone.
>
>I was wondering if it is possible to embed ipa modules in a python virtual
>environment ?
>Or is it too tightly linked with the ipa-client installed on the system ?

You can use
https://pypi.org/project/ipaclient/

$ virtualenv --python=python3.7 here
Running virtualenv with interpreter /usr/bin/python3.7
Using base prefix '/usr'
/usr/lib/python3.7/site-packages/virtualenv.py:1055: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
New python executable in /home/abokovoy/tmp/test-pypi/here/bin/python3.7
Also creating executable in /home/abokovoy/tmp/test-pypi/here/bin/python
Installing setuptools, pip, wheel...done.
$ cd here
$ source bin/activate
(here) $ pip install ipaclient
Collecting ipaclient
  Downloading https://files.pythonhosted.org/packages/5a/f6/8169c2f40f3adb34c3928a3d3f2a12cda297cfa8fb1b600bb6735ddebc31/ipaclient-4.8.1-py2.py3-none-any.whl (601kB)
     |████████████████████████████████| 604kB 1.5MB/s
Collecting ipapython==4.8.1 (from ipaclient)
  Downloading https://files.pythonhosted.org/packages/8a/60/25919c8f5029a2c43fd236fa56375e37c256e60142b4ba6ed599bfd67b30/ipapython-4.8.1-py2.py3-none-any.whl (111kB)
     |████████████████████████████████| 112kB 10.1MB/s
Collecting cryptography>=1.6 (from ipaclient)
  Downloading https://files.pythonhosted.org/packages/97/18/c6557f63a6abde34707196fb2cad1c6dc0dbff25a200d5044922496668a4/cryptography-2.7-cp34-abi3-manylinux1_x86_64.whl (2.3MB)
     |████████████████████████████████| 2.3MB 9.4MB/s
Collecting six (from ipaclient)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting qrcode>=5.0 (from ipaclient)
  Using cached https://files.pythonhosted.org/packages/42/87/4a3a77e59ab7493d64da1f69bf1c2e899a4cf81e51b2baa855e8cc8115be/qrcode-6.1-py2.py3-none-any.whl
Collecting ipalib==4.8.1 (from ipaclient)
  Downloading https://files.pythonhosted.org/packages/a0/19/807dd72d485f9a77d0ec14d61d5dbed7e0432e9b3a67b96b7ec5f2c72dd9/ipalib-4.8.1-py2.py3-none-any.whl (166kB)
     |████████████████████████████████| 174kB 9.9MB/s
Collecting netaddr (from ipapython==4.8.1->ipaclient)
  Using cached https://files.pythonhosted.org/packages/ba/97/ce14451a9fd7bdb5a397abf99b24a1a6bb7a1a440b019bebd2e9a0dbec74/netaddr-0.7.19-py2.py3-none-any.whl
Collecting ipaplatform==4.8.1 (from ipapython==4.8.1->ipaclient)
  Downloading https://files.pythonhosted.org/packages/ff/34/362e07243fa6314bd618ced3ce67bfc21cdfb2393ac9cb72c35df502512a/ipaplatform-4.8.1-py2.py3-none-any.whl (66kB)
     |████████████████████████████████| 71kB 8.5MB/s
Collecting gssapi>=1.2.0 (from ipapython==4.8.1->ipaclient)
  Downloading https://files.pythonhosted.org/packages/21/00/61ab7b1e246787ef32e3122011a418f906ec4c8c60ae7fd6e07956b8d611/gssapi-1.6.1.tar.gz (1.0MB)
     |████████████████████████████████| 1.0MB 9.4MB/s
Collecting cffi (from ipapython==4.8.1->ipaclient)
  Using cached https://files.pythonhosted.org/packages/a0/ea/37fe21475c884f88a2ae496cab10e8f84f0cc11137be860af9eb37a3edb9/cffi-1.12.3-cp37-cp37m-manylinux1_x86_64.whl
Collecting dnspython>=1.15 (from ipapython==4.8.1->ipaclient)
  Using cached https://files.pythonhosted.org/packages/ec/d3/3aa0e7213ef72b8585747aa0e271a9523e713813b9a20177ebe1e939deb0/dnspython-1.16.0-py2.py3-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=1.6->ipaclient)
  Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl
Collecting pyasn1 (from ipalib==4.8.1->ipaclient)
  Downloading https://files.pythonhosted.org/packages/6a/6e/209351ec34b7d7807342e2bb6ff8a96eef1fd5dcac13bdbadf065c2bb55c/pyasn1-0.4.6-py2.py3-none-any.whl (75kB)
     |████████████████████████████████| 81kB 11.4MB/s
Collecting pyasn1-modules (from ipalib==4.8.1->ipaclient)
  Downloading https://files.pythonhosted.org/packages/be/70/e5ea8afd6d08a4b99ebfc77bd1845248d56cfcf43d11f9dc324b9580a35c/pyasn1_modules-0.2.6-py2.py3-none-any.whl (95kB)
     |████████████████████████████████| 102kB 9.7MB/s
Collecting decorator (from gssapi>=1.2.0->ipapython==4.8.1->ipaclient)
  Using cached https://files.pythonhosted.org/packages/5f/88/0075e461560a1e750a0dcbf77f1d9de775028c37a19a346a6c565a257399/decorator-4.4.0-py2.py3-none-any.whl
Collecting pycparser (from cffi->ipapython==4.8.1->ipaclient)
Building wheels for collected packages: gssapi
  Building wheel for gssapi (setup.py) ... done
  Created wheel for gssapi: filename=gssapi-1.6.1-cp37-cp37m-linux_x86_64.whl size=2822815 sha256=25a77bc9efceeee48e54044cd119b9be56df997e885e6add8980c5e778c27b6b
  Stored in directory: /home/abokovoy/.cache/pip/wheels/e6/14/54/6bba9edd808d0ce1680d0212b28a41a98f284a3ee83ae7d44a
Successfully built gssapi
Installing collected packages: netaddr, six, pycparser, cffi, pyasn1, ipaplatform, asn1crypto, cryptography, decorator, gssapi, dnspython, ipapython, qrcode, pyasn1-modules, ipalib, ipaclient
Successfully installed asn1crypto-0.24.0 cffi-1.12.3 cryptography-2.7 decorator-4.4.0 dnspython-1.16.0 gssapi-1.6.1 ipaclient-4.8.1 ipalib-4.8.1 ipaplatform-4.8.1 ipapython-4.8.1 netaddr-0.7.19 pyasn1-0.4.6 pyasn1-modules-0.2.6 pycparser-2.19 qrcode-6.1 six-1.12.0
(here) $ ls bin
activate  activate.csh  activate.fish  activate_this.py  easy_install  easy_install-3.7  ipa  netaddr  pip  pip3  pip3.7  python  python3  python3.7  python-config  qr  wheel
(here) $ which ipa
~/tmp/test-pypi/here/bin/ipa
(here) $ ipa ping
-------------------------------------------
IPA server version 4.7.2. API version 2.230
-------------------------------------------


--
/ Alexander Bokovoy
Sr. Principal Software Engineer
Security / Identity Management Engineering
Red Hat Limited, Finland