canonical / pylxd

Python module for LXD
https://pylxd.readthedocs.io/en/latest/
Apache License 2.0
251 stars 133 forks source link

instance(all): added passing recursion to all method to get all information in instance #551

Closed MrDaGree closed 11 months ago

MrDaGree commented 11 months ago

Resolves #548.

I have a project that I am working on that needs to support multi threading. Having pylxd make multiple http calls unfortunately makes my project a lot more complicated due to this. Instead of making something hacky in my project I decided to implement this to help my project and also implement more of the core LXD api.

Current implementation of instances.all()

>>> for instance in client.instances.all():
...   print(instance.profiles)
... 
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances?recursion=0 HTTP/1.1" 200 991
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances/exampleinstance1 HTTP/1.1" 200 1910
['default']
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances/exampleinstance2 HTTP/1.1" 200 1890
['default']
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances/exampleinstance3 HTTP/1.1" 200 None
['default']
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances/exampleinstance4 HTTP/1.1" 200 1331
['default']
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances/exampleinstance5 HTTP/1.1" 200 None
['default']

With this PR:

>>> for instance in client.instances.all(recursion=2):
...   print(instance.profiles)
... 
DEBUG:urllib3.connectionpool:https://dgreeley-test.mydomain.com:8443 "GET /1.0/instances?recursion=2 HTTP/1.1" 200 None
['default']
['default']
['default']
['default']
['default']
MrDaGree commented 11 months ago

Thank you for the feed back! Ill get this worked in here shortly for another review

markylaing commented 11 months ago

The changes look great thanks. Could you please squash the two commits into one though? Thanks.

MrDaGree commented 11 months ago

Wonderful! Squashed

markylaing commented 11 months ago

Ahh we've renamed master to main so that workflow is failing. Once #552 is merged we'll just need a quick rebase and we should be sorted.

MrDaGree commented 11 months ago

Sounds good. I've subscribed myself so then I can get notification of that so I am on top of this

MrDaGree commented 11 months ago

Rebased from the merge of #552