Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
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
43 changes: 43 additions & 0 deletions openstack/rds/v3/backups/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package backups

import (
"github.com/huaweicloud/golangsdk"
)

var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}

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

// UpdateOpts contains all the values needed to update a Backup.
type UpdateOpts struct {
//Keep Days
KeepDays *int `json:"keep_days" required:"true"`
//Start Time
StartTime string `json:"start_time,omitempty"`
//Period
Period string `json:"period,omitempty"`
}

// ToBackupUpdateMap builds a update request body from UpdateOpts.
func (opts UpdateOpts) ToBackupUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "backup_policy")
}

// Update accepts a UpdateOpts struct and uses the values to update a Backup.The response code from api is 200
func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToBackupUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders}
_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
return
}
10 changes: 10 additions & 0 deletions openstack/rds/v3/backups/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package backups

import (
"github.com/huaweicloud/golangsdk"
)

// UpdateResult represents the result of a update operation.
type UpdateResult struct {
golangsdk.ErrResult
}
7 changes: 7 additions & 0 deletions openstack/rds/v3/backups/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package backups

import "github.com/huaweicloud/golangsdk"

func resourceURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL("instances", id, "backups/policy")
}