Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0538f51

Browse files
committed
core: add missing Builder interfaces
1 parent dd3f103 commit 0538f51

File tree

22 files changed

+179
-36
lines changed

22 files changed

+179
-36
lines changed

openstack/blockstorage/v2/backups/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, o
238238
return
239239
}
240240

241+
// RestoreOptsBuilder allows extensions to add additional parameters to the
242+
// Restore request.
243+
type RestoreOptsBuilder interface {
244+
ToRestoreMap() (map[string]any, error)
245+
}
246+
241247
// RestoreOpts contains options for restoring a Backup. This object is passed to
242248
// the backups.RestoreFromBackup function.
243249
type RestoreOpts struct {
@@ -257,7 +263,7 @@ func (opts RestoreOpts) ToRestoreMap() (map[string]any, error) {
257263
// RestoreFromBackup will restore a Backup to a volume based on the values in
258264
// RestoreOpts. To extract the Restore object from the response, call the
259265
// Extract method on the RestoreResult.
260-
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOpts) (r RestoreResult) {
266+
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOptsBuilder) (r RestoreResult) {
261267
b, err := opts.ToRestoreMap()
262268
if err != nil {
263269
r.Err = err
@@ -278,6 +284,12 @@ func Export(ctx context.Context, client *gophercloud.ServiceClient, id string) (
278284
return
279285
}
280286

287+
// ImportOptsBuilder allows extensions to add additional parameters to the
288+
// Import request.
289+
type ImportOptsBuilder interface {
290+
ToBackupImportMap() (map[string]any, error)
291+
}
292+
281293
// ImportOpts contains options for importing a Backup. This object is passed to
282294
// the backups.ImportBackup function.
283295
type ImportOpts BackupRecord
@@ -291,7 +303,7 @@ func (opts ImportOpts) ToBackupImportMap() (map[string]any, error) {
291303
// Import will import a Backup data to a backup based on the values in
292304
// ImportOpts. To extract the Backup object from the response, call the
293305
// Extract method on the ImportResult.
294-
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOpts) (r ImportResult) {
306+
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOptsBuilder) (r ImportResult) {
295307
b, err := opts.ToBackupImportMap()
296308
if err != nil {
297309
r.Err = err

openstack/blockstorage/v2/transfers/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"github.com/gophercloud/gophercloud/v2/pagination"
88
)
99

10+
// CreateOptsBuilder allows extensions to add additional parameters to the
11+
// Create request.
12+
type CreateOptsBuilder interface {
13+
ToCreateMap() (map[string]any, error)
14+
}
15+
1016
// CreateOpts contains options for a Volume transfer.
1117
type CreateOpts struct {
1218
// The ID of the volume to transfer.
@@ -23,7 +29,7 @@ func (opts CreateOpts) ToCreateMap() (map[string]any, error) {
2329
}
2430

2531
// Create will create a volume tranfer request based on the values in CreateOpts.
26-
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOpts) (r CreateResult) {
32+
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
2733
b, err := opts.ToCreateMap()
2834
if err != nil {
2935
r.Err = err
@@ -36,6 +42,12 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateO
3642
return
3743
}
3844

45+
// AcceptOptsBuilder allows extensions to add additional parameters to the
46+
// Accept request.
47+
type AcceptOptsBuilder interface {
48+
ToAcceptMap() (map[string]any, error)
49+
}
50+
3951
// AcceptOpts contains options for a Volume transfer accept reqeust.
4052
type AcceptOpts struct {
4153
// The auth key of the volume transfer to accept.
@@ -49,7 +61,7 @@ func (opts AcceptOpts) ToAcceptMap() (map[string]any, error) {
4961
}
5062

5163
// Accept will accept a volume tranfer request based on the values in AcceptOpts.
52-
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOpts) (r CreateResult) {
64+
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOptsBuilder) (r CreateResult) {
5365
b, err := opts.ToAcceptMap()
5466
if err != nil {
5567
r.Err = err

openstack/blockstorage/v2/volumes/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ func SetImageMetadata(ctx context.Context, client *gophercloud.ServiceClient, id
617617
return
618618
}
619619

620+
// BootableOptsBuilder allows extensions to add additional parameters to the
621+
// SetBootable request.
622+
type BootableOptsBuilder interface {
623+
ToBootableMap() (map[string]any, error)
624+
}
625+
620626
// BootableOpts contains options for setting bootable status to a volume.
621627
type BootableOpts struct {
622628
// Enables or disables the bootable attribute. You can boot an instance from a bootable volume.
@@ -630,7 +636,7 @@ func (opts BootableOpts) ToBootableMap() (map[string]any, error) {
630636
}
631637

632638
// SetBootable will set bootable status on a volume based on the values in BootableOpts
633-
func SetBootable(ctx context.Context, client *gophercloud.ServiceClient, id string, opts BootableOpts) (r SetBootableResult) {
639+
func SetBootable(ctx context.Context, client *gophercloud.ServiceClient, id string, opts BootableOptsBuilder) (r SetBootableResult) {
634640
b, err := opts.ToBootableMap()
635641
if err != nil {
636642
r.Err = err
@@ -691,6 +697,12 @@ func ChangeType(ctx context.Context, client *gophercloud.ServiceClient, id strin
691697
return
692698
}
693699

700+
// ReImageOptsBuilder allows extensions to add additional parameters to the
701+
// ReImage request.
702+
type ReImageOptsBuilder interface {
703+
ToReImageMap() (map[string]any, error)
704+
}
705+
694706
// ReImageOpts contains options for Re-image a volume.
695707
type ReImageOpts struct {
696708
// New image id
@@ -705,7 +717,7 @@ func (opts ReImageOpts) ToReImageMap() (map[string]any, error) {
705717
}
706718

707719
// ReImage will re-image a volume based on the values in ReImageOpts
708-
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOpts) (r ReImageResult) {
720+
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOptsBuilder) (r ReImageResult) {
709721
b, err := opts.ToReImageMap()
710722
if err != nil {
711723
r.Err = err

openstack/blockstorage/v3/backups/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, o
238238
return
239239
}
240240

241+
// RestoreOptsBuilder allows extensions to add additional parameters to the
242+
// Restore request.
243+
type RestoreOptsBuilder interface {
244+
ToRestoreMap() (map[string]any, error)
245+
}
246+
241247
// RestoreOpts contains options for restoring a Backup. This object is passed to
242248
// the backups.RestoreFromBackup function.
243249
type RestoreOpts struct {
@@ -257,7 +263,7 @@ func (opts RestoreOpts) ToRestoreMap() (map[string]any, error) {
257263
// RestoreFromBackup will restore a Backup to a volume based on the values in
258264
// RestoreOpts. To extract the Restore object from the response, call the
259265
// Extract method on the RestoreResult.
260-
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOpts) (r RestoreResult) {
266+
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOptsBuilder) (r RestoreResult) {
261267
b, err := opts.ToRestoreMap()
262268
if err != nil {
263269
r.Err = err
@@ -278,6 +284,12 @@ func Export(ctx context.Context, client *gophercloud.ServiceClient, id string) (
278284
return
279285
}
280286

287+
// ImportOptsBuilder allows extensions to add additional parameters to the
288+
// Import request.
289+
type ImportOptsBuilder interface {
290+
ToBackupImportMap() (map[string]any, error)
291+
}
292+
281293
// ImportOpts contains options for importing a Backup. This object is passed to
282294
// the backups.ImportBackup function.
283295
type ImportOpts BackupRecord
@@ -291,7 +303,7 @@ func (opts ImportOpts) ToBackupImportMap() (map[string]any, error) {
291303
// Import will import a Backup data to a backup based on the values in
292304
// ImportOpts. To extract the Backup object from the response, call the
293305
// Extract method on the ImportResult.
294-
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOpts) (r ImportResult) {
306+
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOptsBuilder) (r ImportResult) {
295307
b, err := opts.ToBackupImportMap()
296308
if err != nil {
297309
r.Err = err

openstack/blockstorage/v3/transfers/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"github.com/gophercloud/gophercloud/v2/pagination"
88
)
99

10+
// CreateOptsBuilder allows extensions to add additional parameters to the
11+
// Create request.
12+
type CreateOptsBuilder interface {
13+
ToCreateMap() (map[string]any, error)
14+
}
15+
1016
// CreateOpts contains options for a Volume transfer.
1117
type CreateOpts struct {
1218
// The ID of the volume to transfer.
@@ -23,7 +29,7 @@ func (opts CreateOpts) ToCreateMap() (map[string]any, error) {
2329
}
2430

2531
// Create will create a volume tranfer request based on the values in CreateOpts.
26-
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOpts) (r CreateResult) {
32+
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
2733
b, err := opts.ToCreateMap()
2834
if err != nil {
2935
r.Err = err
@@ -36,6 +42,12 @@ func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateO
3642
return
3743
}
3844

45+
// AcceptOptsBuilder allows extensions to add additional parameters to the
46+
// Accept request.
47+
type AcceptOptsBuilder interface {
48+
ToAcceptMap() (map[string]any, error)
49+
}
50+
3951
// AcceptOpts contains options for a Volume transfer accept reqeust.
4052
type AcceptOpts struct {
4153
// The auth key of the volume transfer to accept.
@@ -49,7 +61,7 @@ func (opts AcceptOpts) ToAcceptMap() (map[string]any, error) {
4961
}
5062

5163
// Accept will accept a volume tranfer request based on the values in AcceptOpts.
52-
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOpts) (r CreateResult) {
64+
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOptsBuilder) (r CreateResult) {
5365
b, err := opts.ToAcceptMap()
5466
if err != nil {
5567
r.Err = err

openstack/blockstorage/v3/volumes/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,12 @@ func SetImageMetadata(ctx context.Context, client *gophercloud.ServiceClient, id
623623
return
624624
}
625625

626+
// BootableOptsBuilder allows extensions to add additional parameters to the
627+
// SetBootable request.
628+
type BootableOptsBuilder interface {
629+
ToBootableMap() (map[string]any, error)
630+
}
631+
626632
// BootableOpts contains options for setting bootable status to a volume.
627633
type BootableOpts struct {
628634
// Enables or disables the bootable attribute. You can boot an instance from a bootable volume.
@@ -636,7 +642,7 @@ func (opts BootableOpts) ToBootableMap() (map[string]any, error) {
636642
}
637643

638644
// SetBootable will set bootable status on a volume based on the values in BootableOpts
639-
func SetBootable(ctx context.Context, client *gophercloud.ServiceClient, id string, opts BootableOpts) (r SetBootableResult) {
645+
func SetBootable(ctx context.Context, client *gophercloud.ServiceClient, id string, opts BootableOptsBuilder) (r SetBootableResult) {
640646
b, err := opts.ToBootableMap()
641647
if err != nil {
642648
r.Err = err
@@ -697,6 +703,12 @@ func ChangeType(ctx context.Context, client *gophercloud.ServiceClient, id strin
697703
return
698704
}
699705

706+
// ReImageOptsBuilder allows extensions to add additional parameters to the
707+
// ReImage request.
708+
type ReImageOptsBuilder interface {
709+
ToReImageMap() (map[string]any, error)
710+
}
711+
700712
// ReImageOpts contains options for Re-image a volume.
701713
type ReImageOpts struct {
702714
// New image id
@@ -711,7 +723,7 @@ func (opts ReImageOpts) ToReImageMap() (map[string]any, error) {
711723
}
712724

713725
// ReImage will re-image a volume based on the values in ReImageOpts
714-
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOpts) (r ReImageResult) {
726+
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOptsBuilder) (r ReImageResult) {
715727
b, err := opts.ToReImageMap()
716728
if err != nil {
717729
r.Err = err

openstack/compute/v2/aggregates/requests.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
1515
})
1616
}
1717

18+
// CreateOptsBuilder allows extensions to add additional parameters to the
19+
// Create request.
20+
type CreateOptsBuilder interface {
21+
ToAggregatesCreateMap() (map[string]any, error)
22+
}
23+
1824
type CreateOpts struct {
1925
// The name of the host aggregate.
2026
Name string `json:"name" required:"true"`
@@ -31,7 +37,7 @@ func (opts CreateOpts) ToAggregatesCreateMap() (map[string]any, error) {
3137
}
3238

3339
// Create makes a request against the API to create an aggregate.
34-
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOpts) (r CreateResult) {
40+
func Create(ctx context.Context, client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
3541
b, err := opts.ToAggregatesCreateMap()
3642
if err != nil {
3743
r.Err = err
@@ -64,6 +70,12 @@ func Get(ctx context.Context, client *gophercloud.ServiceClient, aggregateID int
6470
return
6571
}
6672

73+
// UpdateOptsBuilder allows extensions to add additional parameters to the
74+
// Update request.
75+
type UpdateOptsBuilder interface {
76+
ToAggregatesUpdateMap() (map[string]any, error)
77+
}
78+
6779
type UpdateOpts struct {
6880
// The name of the host aggregate.
6981
Name string `json:"name,omitempty"`
@@ -80,7 +92,7 @@ func (opts UpdateOpts) ToAggregatesUpdateMap() (map[string]any, error) {
8092
}
8193

8294
// Update makes a request against the API to update a specific aggregate.
83-
func Update(ctx context.Context, client *gophercloud.ServiceClient, aggregateID int, opts UpdateOpts) (r UpdateResult) {
95+
func Update(ctx context.Context, client *gophercloud.ServiceClient, aggregateID int, opts UpdateOptsBuilder) (r UpdateResult) {
8496
v := strconv.Itoa(aggregateID)
8597

8698
b, err := opts.ToAggregatesUpdateMap()

openstack/compute/v2/services/requests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ const (
5151
ServiceDisabled ServiceStatus = "disabled"
5252
)
5353

54+
// UpdateOptsBuilder allows extensions to add additional parameters to the
55+
// Update request.
56+
type UpdateOptsBuilder interface {
57+
ToServiceUpdateMap() (map[string]any, error)
58+
}
59+
5460
// UpdateOpts specifies the base attributes that may be updated on a service.
5561
type UpdateOpts struct {
5662
// Status represents the new service status. One of enabled or disabled.
@@ -70,7 +76,7 @@ func (opts UpdateOpts) ToServiceUpdateMap() (map[string]any, error) {
7076
}
7177

7278
// Update requests that various attributes of the indicated service be changed.
73-
func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
79+
func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
7480
b, err := opts.ToServiceUpdateMap()
7581
if err != nil {
7682
r.Err = err

openstack/identity/v3/ec2credentials/requests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func Get(ctx context.Context, client *gophercloud.ServiceClient, userID string,
2222
return
2323
}
2424

25+
// CreateOptsBuilder allows extensions to add additional parameters to the
26+
// Create request.
27+
type CreateOptsBuilder interface {
28+
ToCredentialCreateMap() (map[string]any, error)
29+
}
30+
2531
// CreateOpts provides options used to create an EC2 credential.
2632
type CreateOpts struct {
2733
// TenantID is the project ID scope of the EC2 credential.
@@ -34,7 +40,7 @@ func (opts CreateOpts) ToCredentialCreateMap() (map[string]any, error) {
3440
}
3541

3642
// Create creates a new EC2 Credential.
37-
func Create(ctx context.Context, client *gophercloud.ServiceClient, userID string, opts CreateOpts) (r CreateResult) {
43+
func Create(ctx context.Context, client *gophercloud.ServiceClient, userID string, opts CreateOptsBuilder) (r CreateResult) {
3844
b, err := opts.ToCredentialCreateMap()
3945
if err != nil {
4046
r.Err = err

openstack/identity/v3/oauth1/requests.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ func GetConsumer(ctx context.Context, client *gophercloud.ServiceClient, id stri
214214
return
215215
}
216216

217+
// UpdateConsumerOptsBuilder allows extensions to add additional parameters to the
218+
// UpdateConsumer request.
219+
type UpdateConsumerOptsBuilder interface {
220+
ToOAuth1UpdateConsumerMap() (map[string]any, error)
221+
}
222+
217223
// UpdateConsumerOpts provides options used to update a consumer.
218224
type UpdateConsumerOpts struct {
219225
// Description is the consumer description.
@@ -227,7 +233,7 @@ func (opts UpdateConsumerOpts) ToOAuth1UpdateConsumerMap() (map[string]any, erro
227233
}
228234

229235
// UpdateConsumer updates an existing Consumer.
230-
func UpdateConsumer(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateConsumerOpts) (r UpdateConsumerResult) {
236+
func UpdateConsumer(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateConsumerOptsBuilder) (r UpdateConsumerResult) {
231237
b, err := opts.ToOAuth1UpdateConsumerMap()
232238
if err != nil {
233239
r.Err = err

openstack/identity/v3/projects/requests.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ func (opts ModifyTagsOpts) ToModifyTagsCreateMap() (map[string]any, error) {
276276
}
277277

278278
// ModifyTags deletes all tags of a project and adds new ones.
279-
func ModifyTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string, opts ModifyTagsOpts) (r ModifyTagsResult) {
280-
279+
func ModifyTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string, opts ModifyTagsOptsBuilder) (r ModifyTagsResult) {
281280
b, err := opts.ToModifyTagsCreateMap()
282281
if err != nil {
283282
r.Err = err

openstack/loadbalancer/v2/flavorprofiles/requests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (opts UpdateOpts) ToFlavorProfileUpdateMap() (map[string]any, error) {
121121

122122
// Update is an operation which modifies the attributes of the specified
123123
// FlavorProfile.
124-
func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
124+
func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
125125
b, err := opts.ToFlavorProfileUpdateMap()
126126
if err != nil {
127127
r.Err = err

0 commit comments

Comments
 (0)