@@ -2,6 +2,7 @@ package openstack
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "reflect"
78 "strings"
@@ -345,13 +346,20 @@ func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp
345346}
346347
347348// TODO(stephenfin): Allow passing aliases to all New${SERVICE}V${VERSION} methods in v3
348- func initClientOpts (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts , clientType string ) (* gophercloud.ServiceClient , error ) {
349+ func initClientOpts (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts , clientType string , version int ) (* gophercloud.ServiceClient , error ) {
349350 sc := new (gophercloud.ServiceClient )
351+
350352 eo .ApplyDefaults (clientType )
353+ if eo .Version != 0 && eo .Version != version {
354+ return sc , errors .New ("Conflict between requested service major version and manually set version" )
355+ }
356+ eo .Version = version
357+
351358 url , err := client .EndpointLocator (eo )
352359 if err != nil {
353360 return sc , err
354361 }
362+
355363 sc .ProviderClient = client
356364 sc .Endpoint = url
357365 sc .Type = clientType
@@ -361,7 +369,7 @@ func initClientOpts(client *gophercloud.ProviderClient, eo gophercloud.EndpointO
361369// NewBareMetalV1 creates a ServiceClient that may be used with the v1
362370// bare metal package.
363371func NewBareMetalV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
364- sc , err := initClientOpts (client , eo , "baremetal" )
372+ sc , err := initClientOpts (client , eo , "baremetal" , 1 )
365373 if ! strings .HasSuffix (strings .TrimSuffix (sc .Endpoint , "/" ), "v1" ) {
366374 sc .ResourceBase = sc .Endpoint + "v1/"
367375 }
@@ -371,25 +379,25 @@ func NewBareMetalV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointO
371379// NewBareMetalIntrospectionV1 creates a ServiceClient that may be used with the v1
372380// bare metal introspection package.
373381func NewBareMetalIntrospectionV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
374- return initClientOpts (client , eo , "baremetal-introspection" )
382+ return initClientOpts (client , eo , "baremetal-introspection" , 1 )
375383}
376384
377385// NewObjectStorageV1 creates a ServiceClient that may be used with the v1
378386// object storage package.
379387func NewObjectStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
380- return initClientOpts (client , eo , "object-store" )
388+ return initClientOpts (client , eo , "object-store" , 1 )
381389}
382390
383391// NewComputeV2 creates a ServiceClient that may be used with the v2 compute
384392// package.
385393func NewComputeV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
386- return initClientOpts (client , eo , "compute" )
394+ return initClientOpts (client , eo , "compute" , 2 )
387395}
388396
389397// NewNetworkV2 creates a ServiceClient that may be used with the v2 network
390398// package.
391399func NewNetworkV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
392- sc , err := initClientOpts (client , eo , "network" )
400+ sc , err := initClientOpts (client , eo , "network" , 2 )
393401 sc .ResourceBase = sc .Endpoint + "v2.0/"
394402 return sc , err
395403}
@@ -398,56 +406,56 @@ func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpt
398406// NewBlockStorageV1 creates a ServiceClient that may be used to access the v1
399407// block storage service.
400408func NewBlockStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
401- return initClientOpts (client , eo , "volume" )
409+ return initClientOpts (client , eo , "volume" , 1 )
402410}
403411
404412// NewBlockStorageV2 creates a ServiceClient that may be used to access the v2
405413// block storage service.
406414func NewBlockStorageV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
407- return initClientOpts (client , eo , "block-storage" )
415+ return initClientOpts (client , eo , "block-storage" , 2 )
408416}
409417
410418// NewBlockStorageV3 creates a ServiceClient that may be used to access the v3 block storage service.
411419func NewBlockStorageV3 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
412- return initClientOpts (client , eo , "block-storage" )
420+ return initClientOpts (client , eo , "block-storage" , 3 )
413421}
414422
415423// NewSharedFileSystemV2 creates a ServiceClient that may be used to access the v2 shared file system service.
416424func NewSharedFileSystemV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
417- return initClientOpts (client , eo , "shared-file-system" )
425+ return initClientOpts (client , eo , "shared-file-system" , 2 )
418426}
419427
420428// NewOrchestrationV1 creates a ServiceClient that may be used to access the v1
421429// orchestration service.
422430func NewOrchestrationV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
423- return initClientOpts (client , eo , "orchestration" )
431+ return initClientOpts (client , eo , "orchestration" , 1 )
424432}
425433
426434// NewDBV1 creates a ServiceClient that may be used to access the v1 DB service.
427435func NewDBV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
428- return initClientOpts (client , eo , "database" )
436+ return initClientOpts (client , eo , "database" , 1 )
429437}
430438
431439// NewDNSV2 creates a ServiceClient that may be used to access the v2 DNS
432440// service.
433441func NewDNSV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
434- sc , err := initClientOpts (client , eo , "dns" )
442+ sc , err := initClientOpts (client , eo , "dns" , 2 )
435443 sc .ResourceBase = sc .Endpoint + "v2/"
436444 return sc , err
437445}
438446
439447// NewImageV2 creates a ServiceClient that may be used to access the v2 image
440448// service.
441449func NewImageV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
442- sc , err := initClientOpts (client , eo , "image" )
450+ sc , err := initClientOpts (client , eo , "image" , 2 )
443451 sc .ResourceBase = sc .Endpoint + "v2/"
444452 return sc , err
445453}
446454
447455// NewLoadBalancerV2 creates a ServiceClient that may be used to access the v2
448456// load balancer service.
449457func NewLoadBalancerV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
450- sc , err := initClientOpts (client , eo , "load-balancer" )
458+ sc , err := initClientOpts (client , eo , "load-balancer" , 2 )
451459
452460 // Fixes edge case having an OpenStack lb endpoint with trailing version number.
453461 endpoint := strings .Replace (sc .Endpoint , "v2.0/" , "" , - 1 )
@@ -459,36 +467,36 @@ func NewLoadBalancerV2(client *gophercloud.ProviderClient, eo gophercloud.Endpoi
459467// NewMessagingV2 creates a ServiceClient that may be used with the v2 messaging
460468// service.
461469func NewMessagingV2 (client * gophercloud.ProviderClient , clientID string , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
462- sc , err := initClientOpts (client , eo , "message" )
470+ sc , err := initClientOpts (client , eo , "message" , 2 )
463471 sc .MoreHeaders = map [string ]string {"Client-ID" : clientID }
464472 return sc , err
465473}
466474
467475// NewContainerV1 creates a ServiceClient that may be used with v1 container package
468476func NewContainerV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
469- return initClientOpts (client , eo , "application-container" )
477+ return initClientOpts (client , eo , "application-container" , 1 )
470478}
471479
472480// NewKeyManagerV1 creates a ServiceClient that may be used with the v1 key
473481// manager service.
474482func NewKeyManagerV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
475- sc , err := initClientOpts (client , eo , "key-manager" )
483+ sc , err := initClientOpts (client , eo , "key-manager" , 1 )
476484 sc .ResourceBase = sc .Endpoint + "v1/"
477485 return sc , err
478486}
479487
480488// NewContainerInfraV1 creates a ServiceClient that may be used with the v1 container infra management
481489// package.
482490func NewContainerInfraV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
483- return initClientOpts (client , eo , "container-infrastructure-management" )
491+ return initClientOpts (client , eo , "container-infrastructure-management" , 1 )
484492}
485493
486494// NewWorkflowV2 creates a ServiceClient that may be used with the v2 workflow management package.
487495func NewWorkflowV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
488- return initClientOpts (client , eo , "workflow" )
496+ return initClientOpts (client , eo , "workflow" , 2 )
489497}
490498
491499// NewPlacementV1 creates a ServiceClient that may be used with the placement package.
492500func NewPlacementV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
493- return initClientOpts (client , eo , "placement" )
501+ return initClientOpts (client , eo , "placement" , 1 )
494502}
0 commit comments