Create a new container in one project with the python "gdapi"

Hello there,
I’m trying to use the gdapi in python.

I’ve seen similar topics but no clear solution, so let’s try:

I can currently create a client how the README says and it works; I can do “read-only” operations like listing projects, containers, hosts and so one.

Now I want to create: stack, service, container.
I can do that with the REST API like:
POST /projects/{$PID}/containers [paramaters]
but how does that map to the gdapi?
The documentation is poor; I have tried to recover a “project handler” with client.by_id_project('myid') but then I have nothing like ‘create’ or ‘post’ in that REST object.

Please could some one help and point me in the right direction?

Thank you,

Hi Paolo,

Yes, the documentation for the python client is exceedingly poor. It is mainly intended as an internal tool we use for writing tests. We don’t put much effort into making it consumable by the day-to-day user.

That said, it works well and we use it for all of our integration and validation tests. Looking at those tests would be the best way to understand how to use it. Here are the validation tests:

And here are the integration tests from our cattle repo:

Both make extensive use of the python client. The clients are wired into the tests through the use of pytest fixtures, so to understand how we are passing around the clients, you’ll need some understanding of those. We create the clients in and use them in the tests themselves.

Good luck!

Hello there,
I’ve finally found a little time to dig more into all of your tests.

Well, it has been very difficult to debug all the (uncommented) common fixture you have there :stuck_out_tongue:
But I’ve reached some outcome, hope this helps others in the future!

Basically your clients in any test have a create_container method inside, which was not in my client (created from the example in the README of the gdapi repo).
But! I’ve finally found the difference from our clients: the one you create has a projects/$[PROJECT_ID]/schemas as a suffix. If I append that to my initial http://${RANCHER_HOST}:${RANCHER_PORT}/v2-beta/ url it finally works, the create_container is now there in the python object :wink: