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

Skip to content

[v2] core: add missing Builder interfaces #3375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions openstack/blockstorage/v2/backups/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, o
return
}

// RestoreOptsBuilder allows extensions to add additional parameters to the
// Restore request.
type RestoreOptsBuilder interface {
ToRestoreMap() (map[string]any, error)
}

// RestoreOpts contains options for restoring a Backup. This object is passed to
// the backups.RestoreFromBackup function.
type RestoreOpts struct {
Expand All @@ -257,7 +263,7 @@ func (opts RestoreOpts) ToRestoreMap() (map[string]any, error) {
// RestoreFromBackup will restore a Backup to a volume based on the values in
// RestoreOpts. To extract the Restore object from the response, call the
// Extract method on the RestoreResult.
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOpts) (r RestoreResult) {
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOptsBuilder) (r RestoreResult) {
b, err := opts.ToRestoreMap()
if err != nil {
r.Err = err
Expand All @@ -278,6 +284,12 @@ func Export(ctx context.Context, client *gophercloud.ServiceClient, id string) (
return
}

// ImportOptsBuilder allows extensions to add additional parameters to the
// Import request.
type ImportOptsBuilder interface {
ToBackupImportMap() (map[string]any, error)
}

// ImportOpts contains options for importing a Backup. This object is passed to
// the backups.ImportBackup function.
type ImportOpts BackupRecord
Expand All @@ -291,7 +303,7 @@ func (opts ImportOpts) ToBackupImportMap() (map[string]any, error) {
// Import will import a Backup data to a backup based on the values in
// ImportOpts. To extract the Backup object from the response, call the
// Extract method on the ImportResult.
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOpts) (r ImportResult) {
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOptsBuilder) (r ImportResult) {
b, err := opts.ToBackupImportMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/blockstorage/v2/transfers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/gophercloud/gophercloud/v2/pagination"
)

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToCreateMap() (map[string]any, error)
}

// CreateOpts contains options for a Volume transfer.
type CreateOpts struct {
// The ID of the volume to transfer.
Expand All @@ -23,7 +29,7 @@ func (opts CreateOpts) ToCreateMap() (map[string]any, error) {
}

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

// AcceptOptsBuilder allows extensions to add additional parameters to the
// Accept request.
type AcceptOptsBuilder interface {
ToAcceptMap() (map[string]any, error)
}

// AcceptOpts contains options for a Volume transfer accept reqeust.
type AcceptOpts struct {
// The auth key of the volume transfer to accept.
Expand All @@ -49,7 +61,7 @@ func (opts AcceptOpts) ToAcceptMap() (map[string]any, error) {
}

// Accept will accept a volume tranfer request based on the values in AcceptOpts.
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOpts) (r CreateResult) {
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOptsBuilder) (r CreateResult) {
b, err := opts.ToAcceptMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/blockstorage/v2/volumes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ func SetImageMetadata(ctx context.Context, client *gophercloud.ServiceClient, id
return
}

// BootableOptsBuilder allows extensions to add additional parameters to the
// SetBootable request.
type BootableOptsBuilder interface {
ToBootableMap() (map[string]any, error)
}

// BootableOpts contains options for setting bootable status to a volume.
type BootableOpts struct {
// Enables or disables the bootable attribute. You can boot an instance from a bootable volume.
Expand All @@ -630,7 +636,7 @@ func (opts BootableOpts) ToBootableMap() (map[string]any, error) {
}

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

// ReImageOptsBuilder allows extensions to add additional parameters to the
// ReImage request.
type ReImageOptsBuilder interface {
ToReImageMap() (map[string]any, error)
}

// ReImageOpts contains options for Re-image a volume.
type ReImageOpts struct {
// New image id
Expand All @@ -705,7 +717,7 @@ func (opts ReImageOpts) ToReImageMap() (map[string]any, error) {
}

// ReImage will re-image a volume based on the values in ReImageOpts
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOpts) (r ReImageResult) {
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOptsBuilder) (r ReImageResult) {
b, err := opts.ToReImageMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/blockstorage/v3/backups/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, o
return
}

// RestoreOptsBuilder allows extensions to add additional parameters to the
// Restore request.
type RestoreOptsBuilder interface {
ToRestoreMap() (map[string]any, error)
}

// RestoreOpts contains options for restoring a Backup. This object is passed to
// the backups.RestoreFromBackup function.
type RestoreOpts struct {
Expand All @@ -257,7 +263,7 @@ func (opts RestoreOpts) ToRestoreMap() (map[string]any, error) {
// RestoreFromBackup will restore a Backup to a volume based on the values in
// RestoreOpts. To extract the Restore object from the response, call the
// Extract method on the RestoreResult.
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOpts) (r RestoreResult) {
func RestoreFromBackup(ctx context.Context, client *gophercloud.ServiceClient, id string, opts RestoreOptsBuilder) (r RestoreResult) {
b, err := opts.ToRestoreMap()
if err != nil {
r.Err = err
Expand All @@ -278,6 +284,12 @@ func Export(ctx context.Context, client *gophercloud.ServiceClient, id string) (
return
}

// ImportOptsBuilder allows extensions to add additional parameters to the
// Import request.
type ImportOptsBuilder interface {
ToBackupImportMap() (map[string]any, error)
}

// ImportOpts contains options for importing a Backup. This object is passed to
// the backups.ImportBackup function.
type ImportOpts BackupRecord
Expand All @@ -291,7 +303,7 @@ func (opts ImportOpts) ToBackupImportMap() (map[string]any, error) {
// Import will import a Backup data to a backup based on the values in
// ImportOpts. To extract the Backup object from the response, call the
// Extract method on the ImportResult.
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOpts) (r ImportResult) {
func Import(ctx context.Context, client *gophercloud.ServiceClient, opts ImportOptsBuilder) (r ImportResult) {
b, err := opts.ToBackupImportMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/blockstorage/v3/transfers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/gophercloud/gophercloud/v2/pagination"
)

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToCreateMap() (map[string]any, error)
}

// CreateOpts contains options for a Volume transfer.
type CreateOpts struct {
// The ID of the volume to transfer.
Expand All @@ -23,7 +29,7 @@ func (opts CreateOpts) ToCreateMap() (map[string]any, error) {
}

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

// AcceptOptsBuilder allows extensions to add additional parameters to the
// Accept request.
type AcceptOptsBuilder interface {
ToAcceptMap() (map[string]any, error)
}

// AcceptOpts contains options for a Volume transfer accept reqeust.
type AcceptOpts struct {
// The auth key of the volume transfer to accept.
Expand All @@ -49,7 +61,7 @@ func (opts AcceptOpts) ToAcceptMap() (map[string]any, error) {
}

// Accept will accept a volume tranfer request based on the values in AcceptOpts.
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOpts) (r CreateResult) {
func Accept(ctx context.Context, client *gophercloud.ServiceClient, id string, opts AcceptOptsBuilder) (r CreateResult) {
b, err := opts.ToAcceptMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/blockstorage/v3/volumes/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,12 @@ func SetImageMetadata(ctx context.Context, client *gophercloud.ServiceClient, id
return
}

// BootableOptsBuilder allows extensions to add additional parameters to the
// SetBootable request.
type BootableOptsBuilder interface {
ToBootableMap() (map[string]any, error)
}

// BootableOpts contains options for setting bootable status to a volume.
type BootableOpts struct {
// Enables or disables the bootable attribute. You can boot an instance from a bootable volume.
Expand All @@ -636,7 +642,7 @@ func (opts BootableOpts) ToBootableMap() (map[string]any, error) {
}

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

// ReImageOptsBuilder allows extensions to add additional parameters to the
// ReImage request.
type ReImageOptsBuilder interface {
ToReImageMap() (map[string]any, error)
}

// ReImageOpts contains options for Re-image a volume.
type ReImageOpts struct {
// New image id
Expand All @@ -711,7 +723,7 @@ func (opts ReImageOpts) ToReImageMap() (map[string]any, error) {
}

// ReImage will re-image a volume based on the values in ReImageOpts
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOpts) (r ReImageResult) {
func ReImage(ctx context.Context, client *gophercloud.ServiceClient, id string, opts ReImageOptsBuilder) (r ReImageResult) {
b, err := opts.ToReImageMap()
if err != nil {
r.Err = err
Expand Down
16 changes: 14 additions & 2 deletions openstack/compute/v2/aggregates/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ func List(client *gophercloud.ServiceClient) pagination.Pager {
})
}

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToAggregatesCreateMap() (map[string]any, error)
}

type CreateOpts struct {
// The name of the host aggregate.
Name string `json:"name" required:"true"`
Expand All @@ -31,7 +37,7 @@ func (opts CreateOpts) ToAggregatesCreateMap() (map[string]any, error) {
}

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

// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToAggregatesUpdateMap() (map[string]any, error)
}

type UpdateOpts struct {
// The name of the host aggregate.
Name string `json:"name,omitempty"`
Expand All @@ -80,7 +92,7 @@ func (opts UpdateOpts) ToAggregatesUpdateMap() (map[string]any, error) {
}

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

b, err := opts.ToAggregatesUpdateMap()
Expand Down
8 changes: 7 additions & 1 deletion openstack/compute/v2/services/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const (
ServiceDisabled ServiceStatus = "disabled"
)

// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToServiceUpdateMap() (map[string]any, error)
}

// UpdateOpts specifies the base attributes that may be updated on a service.
type UpdateOpts struct {
// Status represents the new service status. One of enabled or disabled.
Expand All @@ -70,7 +76,7 @@ func (opts UpdateOpts) ToServiceUpdateMap() (map[string]any, error) {
}

// Update requests that various attributes of the indicated service be changed.
func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
func Update(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToServiceUpdateMap()
if err != nil {
r.Err = err
Expand Down
8 changes: 7 additions & 1 deletion openstack/identity/v3/ec2credentials/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func Get(ctx context.Context, client *gophercloud.ServiceClient, userID string,
return
}

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToCredentialCreateMap() (map[string]any, error)
}

// CreateOpts provides options used to create an EC2 credential.
type CreateOpts struct {
// TenantID is the project ID scope of the EC2 credential.
Expand All @@ -34,7 +40,7 @@ func (opts CreateOpts) ToCredentialCreateMap() (map[string]any, error) {
}

// Create creates a new EC2 Credential.
func Create(ctx context.Context, client *gophercloud.ServiceClient, userID string, opts CreateOpts) (r CreateResult) {
func Create(ctx context.Context, client *gophercloud.ServiceClient, userID string, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToCredentialCreateMap()
if err != nil {
r.Err = err
Expand Down
8 changes: 7 additions & 1 deletion openstack/identity/v3/oauth1/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ func GetConsumer(ctx context.Context, client *gophercloud.ServiceClient, id stri
return
}

// UpdateConsumerOptsBuilder allows extensions to add additional parameters to the
// UpdateConsumer request.
type UpdateConsumerOptsBuilder interface {
ToOAuth1UpdateConsumerMap() (map[string]any, error)
}

// UpdateConsumerOpts provides options used to update a consumer.
type UpdateConsumerOpts struct {
// Description is the consumer description.
Expand All @@ -227,7 +233,7 @@ func (opts UpdateConsumerOpts) ToOAuth1UpdateConsumerMap() (map[string]any, erro
}

// UpdateConsumer updates an existing Consumer.
func UpdateConsumer(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateConsumerOpts) (r UpdateConsumerResult) {
func UpdateConsumer(ctx context.Context, client *gophercloud.ServiceClient, id string, opts UpdateConsumerOptsBuilder) (r UpdateConsumerResult) {
b, err := opts.ToOAuth1UpdateConsumerMap()
if err != nil {
r.Err = err
Expand Down
3 changes: 1 addition & 2 deletions openstack/identity/v3/projects/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ func (opts ModifyTagsOpts) ToModifyTagsCreateMap() (map[string]any, error) {
}

// ModifyTags deletes all tags of a project and adds new ones.
func ModifyTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string, opts ModifyTagsOpts) (r ModifyTagsResult) {

func ModifyTags(ctx context.Context, client *gophercloud.ServiceClient, projectID string, opts ModifyTagsOptsBuilder) (r ModifyTagsResult) {
b, err := opts.ToModifyTagsCreateMap()
if err != nil {
r.Err = err
Expand Down
2 changes: 1 addition & 1 deletion openstack/loadbalancer/v2/flavorprofiles/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (opts UpdateOpts) ToFlavorProfileUpdateMap() (map[string]any, error) {

// Update is an operation which modifies the attributes of the specified
// FlavorProfile.
func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) {
func Update(ctx context.Context, c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToFlavorProfileUpdateMap()
if err != nil {
r.Err = err
Expand Down
Loading
Loading