@@ -2,6 +2,7 @@ package openstack
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
"fmt"
6
7
"reflect"
7
8
"strings"
@@ -345,13 +346,20 @@ func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp
345
346
}
346
347
347
348
// 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 ) {
349
350
sc := new (gophercloud.ServiceClient )
351
+
350
352
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
+
351
358
url , err := client .EndpointLocator (eo )
352
359
if err != nil {
353
360
return sc , err
354
361
}
362
+
355
363
sc .ProviderClient = client
356
364
sc .Endpoint = url
357
365
sc .Type = clientType
@@ -361,7 +369,7 @@ func initClientOpts(client *gophercloud.ProviderClient, eo gophercloud.EndpointO
361
369
// NewBareMetalV1 creates a ServiceClient that may be used with the v1
362
370
// bare metal package.
363
371
func 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 )
365
373
if ! strings .HasSuffix (strings .TrimSuffix (sc .Endpoint , "/" ), "v1" ) {
366
374
sc .ResourceBase = sc .Endpoint + "v1/"
367
375
}
@@ -371,25 +379,25 @@ func NewBareMetalV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointO
371
379
// NewBareMetalIntrospectionV1 creates a ServiceClient that may be used with the v1
372
380
// bare metal introspection package.
373
381
func 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 )
375
383
}
376
384
377
385
// NewObjectStorageV1 creates a ServiceClient that may be used with the v1
378
386
// object storage package.
379
387
func 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 )
381
389
}
382
390
383
391
// NewComputeV2 creates a ServiceClient that may be used with the v2 compute
384
392
// package.
385
393
func NewComputeV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
386
- return initClientOpts (client , eo , "compute" )
394
+ return initClientOpts (client , eo , "compute" , 2 )
387
395
}
388
396
389
397
// NewNetworkV2 creates a ServiceClient that may be used with the v2 network
390
398
// package.
391
399
func 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 )
393
401
sc .ResourceBase = sc .Endpoint + "v2.0/"
394
402
return sc , err
395
403
}
@@ -398,56 +406,56 @@ func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpt
398
406
// NewBlockStorageV1 creates a ServiceClient that may be used to access the v1
399
407
// block storage service.
400
408
func NewBlockStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
401
- return initClientOpts (client , eo , "volume" )
409
+ return initClientOpts (client , eo , "volume" , 1 )
402
410
}
403
411
404
412
// NewBlockStorageV2 creates a ServiceClient that may be used to access the v2
405
413
// block storage service.
406
414
func 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 )
408
416
}
409
417
410
418
// NewBlockStorageV3 creates a ServiceClient that may be used to access the v3 block storage service.
411
419
func 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 )
413
421
}
414
422
415
423
// NewSharedFileSystemV2 creates a ServiceClient that may be used to access the v2 shared file system service.
416
424
func 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 )
418
426
}
419
427
420
428
// NewOrchestrationV1 creates a ServiceClient that may be used to access the v1
421
429
// orchestration service.
422
430
func NewOrchestrationV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
423
- return initClientOpts (client , eo , "orchestration" )
431
+ return initClientOpts (client , eo , "orchestration" , 1 )
424
432
}
425
433
426
434
// NewDBV1 creates a ServiceClient that may be used to access the v1 DB service.
427
435
func NewDBV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
428
- return initClientOpts (client , eo , "database" )
436
+ return initClientOpts (client , eo , "database" , 1 )
429
437
}
430
438
431
439
// NewDNSV2 creates a ServiceClient that may be used to access the v2 DNS
432
440
// service.
433
441
func 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 )
435
443
sc .ResourceBase = sc .Endpoint + "v2/"
436
444
return sc , err
437
445
}
438
446
439
447
// NewImageV2 creates a ServiceClient that may be used to access the v2 image
440
448
// service.
441
449
func 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 )
443
451
sc .ResourceBase = sc .Endpoint + "v2/"
444
452
return sc , err
445
453
}
446
454
447
455
// NewLoadBalancerV2 creates a ServiceClient that may be used to access the v2
448
456
// load balancer service.
449
457
func 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 )
451
459
452
460
// Fixes edge case having an OpenStack lb endpoint with trailing version number.
453
461
endpoint := strings .Replace (sc .Endpoint , "v2.0/" , "" , - 1 )
@@ -459,36 +467,36 @@ func NewLoadBalancerV2(client *gophercloud.ProviderClient, eo gophercloud.Endpoi
459
467
// NewMessagingV2 creates a ServiceClient that may be used with the v2 messaging
460
468
// service.
461
469
func 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 )
463
471
sc .MoreHeaders = map [string ]string {"Client-ID" : clientID }
464
472
return sc , err
465
473
}
466
474
467
475
// NewContainerV1 creates a ServiceClient that may be used with v1 container package
468
476
func 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 )
470
478
}
471
479
472
480
// NewKeyManagerV1 creates a ServiceClient that may be used with the v1 key
473
481
// manager service.
474
482
func 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 )
476
484
sc .ResourceBase = sc .Endpoint + "v1/"
477
485
return sc , err
478
486
}
479
487
480
488
// NewContainerInfraV1 creates a ServiceClient that may be used with the v1 container infra management
481
489
// package.
482
490
func 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 )
484
492
}
485
493
486
494
// NewWorkflowV2 creates a ServiceClient that may be used with the v2 workflow management package.
487
495
func NewWorkflowV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
488
- return initClientOpts (client , eo , "workflow" )
496
+ return initClientOpts (client , eo , "workflow" , 2 )
489
497
}
490
498
491
499
// NewPlacementV1 creates a ServiceClient that may be used with the placement package.
492
500
func NewPlacementV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
493
- return initClientOpts (client , eo , "placement" )
501
+ return initClientOpts (client , eo , "placement" , 1 )
494
502
}
0 commit comments