Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

MrDaGree
Copy link
Contributor

@MrDaGree MrDaGree commented Jul 11, 2023

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']

Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrDaGree thank you for adding this. Prefetching instance attributes will certainly make the client more efficient!

I've just left a couple of comments that I think will help with readability.

pylxd/models/instance.py Outdated Show resolved Hide resolved
pylxd/models/instance.py Outdated Show resolved Hide resolved
pylxd/models/instance.py Outdated Show resolved Hide resolved
@MrDaGree
Copy link
Contributor Author

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

@MrDaGree MrDaGree requested a review from markylaing July 11, 2023 17:25
@markylaing
Copy link
Contributor

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

@MrDaGree MrDaGree force-pushed the dgreeley-instance-all-recursion branch from bb993a3 to 3b7ba60 Compare July 11, 2023 19:36
@MrDaGree
Copy link
Contributor Author

Wonderful! Squashed

@markylaing
Copy link
Contributor

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
Copy link
Contributor Author

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

…mation in instance

Signed-off-by: Dawson Greeley <dawsonmax10@gmail.com>
@MrDaGree MrDaGree force-pushed the dgreeley-instance-all-recursion branch from 3b7ba60 to 98ff395 Compare July 11, 2023 20:49
@MrDaGree
Copy link
Contributor Author

Rebased from the merge of #552

Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@markylaing markylaing merged commit aee4807 into canonical:main Jul 12, 2023
simondeziel added a commit to simondeziel/pylxd that referenced this pull request Jul 13, 2023
This fixes `tox -e coverage`. This was not caught when introduced by
PR canonical#551 because we our CI job was still only triggering on the old
branch name. The CI job was fixed afterward by commit 094bab4.

The decision to omit the recursion param was taken because that's easier
than trying to fix the mocked HTTP responses.

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
simondeziel added a commit to simondeziel/pylxd that referenced this pull request Jul 13, 2023
This fixes `tox -e coverage`. This was not caught when introduced by
PR canonical#551 because we our CI job was still only triggering on the old
branch name. The CI job was fixed afterward by commit 094bab4.

The decision to omit the recursion param was taken because that's easier
than trying to fix the mocked HTTP responses.

Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
@MrDaGree MrDaGree deleted the dgreeley-instance-all-recursion branch August 11, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to pass recursion to client.instances.all()
2 participants