Conversation
…service_client.go
I did a quick inventory here: https://gist.github.com/jtopjian/183bf8c7cb81d0c29717a42b78b9b762 It looks like Cinder v3 supports microversions, but Gophercloud doesn't have v3 support. Glance is questionable. No idea what it's doing.
I think it's OK. I modified the client.Microversion = "2.42"and also did a dump of the request. I saw both headers and the request was successful. I then did an invalid request of: client.Microversion = "2.52"And successfully got: This implementation looks good to me. It's a very clean implementation and I was able to digest it quickly. Absolutely no offence is meant to the other PRs, though. I think this is a fine implementation. I have some other thoughts / questions that I'll add to #53 since they're not code related, but this could easily be a foundation for some other things, if applicable. |
|
Also, I'll do another review and some more testing later and then sign off on it. |
jtopjian
left a comment
There was a problem hiding this comment.
This looks good to me. Existing acceptance tests pass and I was able to alter the microversion header and see that it was being recognized by the API server.
service_client.go
Outdated
| opts.MoreHeaders["X-OpenStack-Nova-API-Version"] = client.Microversion | ||
|
|
||
| return client.Request("DELETE", url, opts) | ||
| opts.MoreHeaders["OpenStack-API-Version"] = client.Type + " " + client.Microversion |
There was a problem hiding this comment.
I would rather check whether client.Type != ""
| switch client.Type { | ||
| case "compute": | ||
| opts.MoreHeaders["X-OpenStack-Nova-API-Version"] = client.Microversion | ||
| case "sharev2": |
There was a problem hiding this comment.
A nit: compute and sharev2 strings can be defined as a const as they are used on more than one place and the semantic meaning in which they are used is the same.
These constants are used in the gophercloud and openstack packages. Because openstack package imports gophercloud package the constants will have to be defined in the gophercloud package because of import cycle even though they semantically belong to openstack package.
There was a problem hiding this comment.
True. That may be something to add later when there are several more client types supporting microversions.
| return &gophercloud.ServiceClient{ProviderClient: client, Endpoint: url}, nil | ||
| sc.ProviderClient = client | ||
| sc.Endpoint = url | ||
| sc.Type = clientType |
There was a problem hiding this comment.
It is assumed that client.EndpointLocator will return an endpoint URL that's service type equals the requested clientType. I think this is fine and it's how client.EndpointLocator works now.
However, there are other service information that are available in func V2EndpointURL and func V3EndpointURL and are not returned by the functions and that may be useful in the gophercloud.ServiceClient struct in the future.
IMHO, we may open the doors for returning these information from the functions by adding one more return value to the EndpointLocator type.
There was a problem hiding this comment.
For me, what you've suggested in #352 is too complex for what's required here. I don't want to throw all information returned from an endpoint into a struct.
There was a problem hiding this comment.
Currently, there is no mechanism for returning information from endpoint that would be easily extensible. That's why I'm proposing to add a struct as a new endpoint return value. The struct can be easily extended in the future and doesn't have to contain all currently available information.
As you introduced the func initClientOpts, the client.EndpointLocator is called at less places than before. So it's now easier to add new return values to the client.EndpointLocator function.
I agree with you solution.
| func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { | ||
| if opts == nil { | ||
| opts = &RequestOpts{} | ||
| func (client *ServiceClient) initReqOpts(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) { |
There was a problem hiding this comment.
I like how the duplicate code is replaced by this function.
* fix microversion header; refactor common operations in client.go and service_client.go * don't add microversion header for nil client type
For #53
Links to the line numbers/files in the OpenStack source code that support the
code in this PR:
https://github.com/openstack/manila/blob/stable/newton/manila/common/config.py#L196
https://github.com/openstack/nova/blob/acfbec7db9a3df5a3183a2730510fa1f0fea92bf/nova/api/openstack/wsgi.py#L68
I think those are the only 2 services that Gophercloud currently supports that offer microversions. It does look like the
X-OpenStack-<SERVICE>-API-Versionheaders are being replaced byOpenStack-API-Version, but are still around for backwards-compatibility, so I'm adding both. Hopefully that won't cause a problem.This is an alternative implementation to the ones in #341 and #352 . I think it's cleaner and doesn't force users to identify the service type.
It also refactors some of the common code when making requests and creating service clients.