From b32a7fb801d7424cddb9f610a2bcc3520b23eab2 Mon Sep 17 00:00:00 2001 From: edisonxiang Date: Thu, 14 Jun 2018 17:14:13 +0800 Subject: [PATCH] fix bugs in dcs --- openstack/dcs/v1/instances/requests.go | 39 +++++++++++++++++++++++++- openstack/dcs/v1/instances/results.go | 5 ++++ openstack/dcs/v1/instances/urls.go | 6 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/openstack/dcs/v1/instances/requests.go b/openstack/dcs/v1/instances/requests.go index c4893d8f3..8015f1d7c 100644 --- a/openstack/dcs/v1/instances/requests.go +++ b/openstack/dcs/v1/instances/requests.go @@ -101,7 +101,7 @@ type InstanceBackupPolicy struct { type PeriodicalBackupPlan struct { // Time at which backup starts. // "00:00-01:00" indicates that backup starts at 00:00:00. - BeginAt int `json:"begin_at" required:"true"` + BeginAt string `json:"begin_at" required:"true"` // Interval at which backup is performed. // Currently, only weekly backup is supported. @@ -238,3 +238,40 @@ func UpdatePassword(client *golangsdk.ServiceClient, id string, opts UpdatePassw }) return } + +//ExtendOptsBuilder is an interface which can build the map paramter of extend function +type ExtendOptsBuilder interface { + ToExtendMap() (map[string]interface{}, error) +} + +//ExtendOpts is a struct which represents the parameters of extend function +type ExtendOpts struct { + // New specifications (memory space) of the DCS instance. + // The new specification value to which the DCS instance + // will be scaled up must be greater than the current specification value. + // Unit: GB. + NewCapacity int `json:"new_capacity" required:"true"` + + // New order ID. + OrderID string `json:"order_id,omitempty"` +} + +// ToExtendMap is used for type convert +func (opts ExtendOpts) ToExtendMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +// Extend is extending for a dcs instance +func Extend(client *golangsdk.ServiceClient, id string, opts ExtendOptsBuilder) (r ExtendResult) { + + body, err := opts.ToExtendMap() + if err != nil { + r.Err = err + return + } + + _, r.Err = client.Post(extendURL(client, id), body, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{204}, + }) + return +} diff --git a/openstack/dcs/v1/instances/results.go b/openstack/dcs/v1/instances/results.go index 7e5553f73..235d78a67 100644 --- a/openstack/dcs/v1/instances/results.go +++ b/openstack/dcs/v1/instances/results.go @@ -104,3 +104,8 @@ func (r UpdatePasswordResult) Extract() (*Password, error) { err := r.Result.ExtractInto(&s) return &s, err } + +// ExtendResult is a struct from which can get the result of extend method +type ExtendResult struct { + golangsdk.Result +} diff --git a/openstack/dcs/v1/instances/urls.go b/openstack/dcs/v1/instances/urls.go index c260a95e1..cb384cc03 100644 --- a/openstack/dcs/v1/instances/urls.go +++ b/openstack/dcs/v1/instances/urls.go @@ -5,6 +5,7 @@ import "github.com/huaweicloud/golangsdk" // endpoint/instances const resourcePath = "instances" const passwordPath = "password" +const extendPath = "extend" // createURL will build the rest query url of creation func createURL(client *golangsdk.ServiceClient) string { @@ -30,3 +31,8 @@ func getURL(client *golangsdk.ServiceClient, id string) string { func passwordURL(client *golangsdk.ServiceClient, id string) string { return client.ServiceURL(resourcePath, id, passwordPath) } + +// extendURL will build the extend update function +func extendURL(client *golangsdk.ServiceClient, id string) string { + return client.ServiceURL(resourcePath, id, extendPath) +}