Skip to content

Commit 8cbcb2f

Browse files
committed
Add new service discovery helper
This is an re-implementation of GetSupportedMicroversions that supports use with a ProviderClient and an explicit endpoint URL, allowing us to use this during discovery. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 2bf97ce commit 8cbcb2f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

openstack/utils/choose_version.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ type SupportedMicroversions struct {
122122
MinMinor int
123123
}
124124

125-
// GetSupportedMicroversions returns the minimum and maximum microversion that is supported by the ServiceClient Endpoint.
126-
func GetSupportedMicroversions(ctx context.Context, client *gophercloud.ServiceClient) (SupportedMicroversions, error) {
125+
// GetServiceVersions returns the minimum and maximum microversion that is supported by the ServiceClient Endpoint.
126+
func GetServiceVersions(ctx context.Context, client *gophercloud.ProviderClient, endpointURL string) (SupportedMicroversions, error) {
127127
type valueResp struct {
128128
ID string `json:"id"`
129129
Status string `json:"status"`
@@ -138,8 +138,9 @@ func GetSupportedMicroversions(ctx context.Context, client *gophercloud.ServiceC
138138
var minVersion, maxVersion string
139139
var supportedMicroversions SupportedMicroversions
140140
var resp response
141-
_, err := client.Get(ctx, client.Endpoint, &resp, &gophercloud.RequestOpts{
142-
OkCodes: []int{200, 300},
141+
_, err := client.Request(ctx, "GET", endpointURL, &gophercloud.RequestOpts{
142+
JSONResponse: &resp,
143+
OkCodes: []int{200, 300},
143144
})
144145

145146
if err != nil {
@@ -161,7 +162,7 @@ func GetSupportedMicroversions(ctx context.Context, client *gophercloud.ServiceC
161162

162163
// Return early if the endpoint does not support microversions
163164
if minVersion == "" && maxVersion == "" {
164-
return supportedMicroversions, fmt.Errorf("microversions not supported by ServiceClient Endpoint")
165+
return supportedMicroversions, fmt.Errorf("microversions not supported by endpoint")
165166
}
166167

167168
supportedMicroversions.MinMajor, supportedMicroversions.MinMinor, err = ParseMicroversion(minVersion)
@@ -177,6 +178,11 @@ func GetSupportedMicroversions(ctx context.Context, client *gophercloud.ServiceC
177178
return supportedMicroversions, nil
178179
}
179180

181+
// GetSupportedMicroversions returns the minimum and maximum microversion that is supported by the ServiceClient Endpoint.
182+
func GetSupportedMicroversions(ctx context.Context, client *gophercloud.ServiceClient) (SupportedMicroversions, error) {
183+
return GetServiceVersions(ctx, client.ProviderClient, client.Endpoint)
184+
}
185+
180186
// RequireMicroversion checks that the required microversion is supported and
181187
// returns a ServiceClient with the microversion set.
182188
func RequireMicroversion(ctx context.Context, client gophercloud.ServiceClient, required string) (gophercloud.ServiceClient, error) {

0 commit comments

Comments
 (0)