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
Updates lxd_container
to support new LXD API
#7980
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
plugins/modules/lxd_container.py
Outdated
# LXD (3.19) Rest API provides instance endpoint, failback to containers and virtual-machines | ||
self.api_endpoint = '/1.0/instances' | ||
try: | ||
self.client.do('GET', '{0}/{1}'.format(self.api_endpoint, ''), ok_error_codes=[404]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check the return value whether it's a 404 error, instead of trying to catch an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When working out the best approach to do this, I found/figured out that this approach would return 404 for endpoints that didn't exist even. For example, /1.0/test
would result in 404 like /1.0/instances
. However, adding the ?project
filter with a blank project would result in the API response I was looking for.
015fecb
to
6e20d71
Compare
This comment was marked as outdated.
This comment was marked as outdated.
The code change looks good to me (as far as I can judge). Can you please add a changelog fragment? Thanks. |
can confirm, runs for me without problems |
(And mark the PR as ready when you think you're done :) ) |
Co-authored-by: Felix Fontein <felix@fontein.de>
Backport to stable-7: 💚 backport PR created✅ Backport PR branch: Backported as #8045 🤖 @patchback |
* feat: ✨ adds support for /1.0/instances endpoint * Update changelogs/fragments/lxd-instances-api-endpoint-added.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 74c15c1)
Backport to stable-8: 💚 backport PR created✅ Backport PR branch: Backported as #8046 🤖 @patchback |
* feat: ✨ adds support for /1.0/instances endpoint * Update changelogs/fragments/lxd-instances-api-endpoint-added.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 74c15c1)
@anthonyra thanks a lot for your contribution! |
…port new LXD API (#8045) Updates `lxd_container` to support new LXD API (#7980) * feat: ✨ adds support for /1.0/instances endpoint * Update changelogs/fragments/lxd-instances-api-endpoint-added.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 74c15c1) Co-authored-by: Anthony Anderson <fnanderson93@gmail.com>
…port new LXD API (#8046) Updates `lxd_container` to support new LXD API (#7980) * feat: ✨ adds support for /1.0/instances endpoint * Update changelogs/fragments/lxd-instances-api-endpoint-added.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 74c15c1) Co-authored-by: Anthony Anderson <fnanderson93@gmail.com>
SUMMARY
Updates the
lxd_container
module to work with the new LXD API which deprecates/1.0/containers
and/1.0/virtual-machines
and adds/1.0/instances
. It tries to keep backwards compatibility with a try and catch compared to detecting the API version then determining which API endpoint to use.Fixes #7853
ISSUE TYPE
COMPONENT NAME
lxd_container
ADDITIONAL INFORMATION