Skip to content

Conversation

@ycalansy
Copy link

Description

This change addresses an issue where the Nova CreateImage API response was not handled correctly for microversion 2.45 and above.

Prior to microversion 2.45, the image ID was extracted from the Location header. Starting with 2.45, Nova no longer includes the Location header. Instead, the image ID is returned in the response body as a small JSON object. (see API reference)

The CreateImage function has been updated to:

  • Read and store the response body in CreateImageResult.
  • Extract the image ID based on the X-OpenStack-Nova-API-Version header:
    • For microversions prior to 2.45, extract from the Location header.
    • For microversion 2.45 and above, extract from the response body.

This fix resolves the issue where the image ID was previously empty for Nova 2.45+, while maintaining compatibility with older microversions.

Fixes #3542

Since microversion 2.45, the Location header is removed from the create image
response. The image ID is now returned in the response body as JSON.

CreateImage now reads the response body and stores it in CreateImageResult.
The image ID extraction checks X-OpenStack-Nova-API-Version to determine
whether to extract the ID from the Location header (< 2.45) or the response
body (>= 2.45).
@github-actions github-actions bot added edit:compute This PR updates compute code semver:patch No API change backport-v2 This PR will be backported to v2 labels Oct 28, 2025
@coveralls
Copy link

Coverage Status

coverage: 63.844% (+0.02%) from 63.823%
when pulling 398a995 on ycalansy:nova-create-image-microversion-aware-id-extraction
into 1b200e1 on gophercloud:main.

return
}

r.Body = &buf
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels overly complex, considering that gophercloud.ParseResponse(resp, err) returns the body as the first return value. Any reason why we're not using it?

Copy link
Author

Choose a reason for hiding this comment

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

gophercloud.ParseResponse(resp, err) hands back the resp.Body, which means the body/connection stays open until the caller consumes and closes it. In this case the payload is small, so we buffer it and close the response immediately to ensure the connection can be reused even if the caller never calls the extract helper.

Copy link
Contributor

@stephenfin stephenfin left a comment

Choose a reason for hiding this comment

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

Per @mandre's comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v2 This PR will be backported to v2 edit:compute This PR updates compute code semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CreateImage returns empty image ID for Nova microversion 2.45+

4 participants