From 0febd237f3a25cb43626ce0b2fabcbce978d2b22 Mon Sep 17 00:00:00 2001 From: duanliguo Date: Sun, 7 Feb 2021 15:11:30 +0800 Subject: [PATCH] Add autorenew in rds and fix docs --- doc/DDC.md | 19 ++++++++++++ doc/RDS.md | 31 ++++++++++++++++++- services/ddc/client_test.go | 50 ++++++++++++++++++------------ services/rds/client_test.go | 20 +++++++++--- services/rds/model.go | 62 ++++++++++++++++++++----------------- services/rds/rds.go | 15 +++++++++ 6 files changed, 144 insertions(+), 53 deletions(-) diff --git a/doc/DDC.md b/doc/DDC.md index 0c8a227b..9146a78b 100644 --- a/doc/DDC.md +++ b/doc/DDC.md @@ -627,6 +627,10 @@ args := &ddc.CreateRdsArgs{ TagValue: "tagV", }, }, + // 部署集id 可选 + DeployId:"xxxyyy-123", + // 资源池id 必选 + PoolId:"xxxyzzzyy-123", } result, err := client.CreateRds(args) if err != nil { @@ -681,6 +685,21 @@ args := &ddc.CreateReadReplicaArgs{ TagValue: "tagV", }, }, + // 部署集id 可选 + DeployId:"xxxyyy-123", + // 资源池id 必选与主实例保持一致 + PoolId:"xxxyzzzyy-123", + // RO组ID。(创建只读实例时) 可选 + // 如果不传,默认会创建一个RO组,并将该只读加入RO组中 + RoGroupId:"yyzzcc", + // RO组是否启用延迟剔除,默认不启动。(创建只读实例时)可选 + EnableDelayOff:false, + // 延迟阈值。(创建只读实例时)可选 + DelayThreshold: 1, + // RO组最少保留实例数目。默认为1. (创建只读实例时)可选 + LeastInstanceAmount: 1, + // 只读实例在RO组中的读流量权重。默认为1(创建只读实例时)可选 + RoGroupWeight: 1, } result, err := client.CreateReadReplica(args) if err != nil { diff --git a/doc/RDS.md b/doc/RDS.md index b2704d07..bf9d1306 100644 --- a/doc/RDS.md +++ b/doc/RDS.md @@ -466,6 +466,7 @@ for _, e := range result.Instances { fmt.Println("rds instanceCreateTime: ", e.InstanceCreateTime) fmt.Println("rds instanceExpireTime: ", e.InstanceExpireTime) fmt.Println("rds publicAccessStatus: ", e.PublicAccessStatus) + fmt.Println("rds task: ", e.Task) fmt.Println("rds vpcId: ", e.VpcId) } ``` @@ -588,11 +589,39 @@ if err != nil { } fmt.Printf("update instance name success\n") ``` - > 注意: > > - 实例名称支持大小写字母、数字以及-_ /.等特殊字符,必须以字母开头,长度1-64。 +## 已创建实例自动续费 + +使用以下代码可以为已创建的预付费实例创建自动续费 +```go +// import "github.com/baidubce/bce-sdk-go/services/rds" + +args := &rds.AutoRenewArgs{ + // 自动续费时长(续费单位为year 不大于3,续费单位为month 不大于9)必选 + AutoRenewTime: 1, + // 自动续费单位("year";"month")必选 + AutoRenewTimeUnit: "year", + // 实例id集合 必选 + InstanceIds: []string{ + "rds-y9dJu77d", + "rds-aQFOoncr", + }, +} +err := client.AutoRenew(args) +if err != nil { + fmt.Printf("create auto renew error: %+v\n", err) + return +} +``` +> 注意: +> +> - 用于已创建的实例开启自动续费。 +> - 可以传入多个实例id,多个实例需保证在同一地域。 + + ## 修改同步模式 使用以下代码可以修改RDS实例同步模式。 diff --git a/services/ddc/client_test.go b/services/ddc/client_test.go index b525a88f..b6e0f259 100644 --- a/services/ddc/client_test.go +++ b/services/ddc/client_test.go @@ -85,26 +85,36 @@ func ExpectEqual(alert func(format string, args ...interface{}), } func TestClient_CreateInstance(t *testing.T) { - //id := strconv.FormatInt(time.Now().Unix(),10) - args := &CreateInstanceArgs{ - - InstanceType: "RDS", - Number: 1, - Instance: CreateInstance{ - Engine: "mysql", - EngineVersion: "5.7", - CpuCount: 1, - AllocatedMemoryInGB: 8, - AllocatedStorageInGB: 10, - AZone: "zoneA", - SubnetId: "zoneA:11c4f322-3a0e-4f26-8883-285cf64d0f03", - DiskIoType: "normal_io", - DeployId: "", - PoolId: "", + args := &CreateRdsArgs{ + PurchaseCount: 1, + InstanceName: "mysql_5.7", + //SourceInstanceId: "ddc-mmqptugx", + Engine: "mysql", + EngineVersion: "5.7", + CpuCount: 1, + MemoryCapacity: 1, + VolumeCapacity: 5, + Billing: Billing{ + PaymentTiming: "Postpaid", + Reservation: Reservation{ReservationLength: 1, ReservationTimeUnit: "Month"}, }, - } - DDC_CLIENT.CreateInstance(args) + VpcId: "vpc-80m2ksi6sv0f", + ZoneNames: []string{ + "cn-su-c", + }, + Subnets: []SubnetMap{ + { + ZoneName: "cn-su-c", + SubnetId: "sbn-8v3p33vhyhq5", + }, + }, + DeployId: "", + PoolId: "xdb_gaiabase_pool", + } + rds, err := DDC_CLIENT.CreateRds(args) + ExpectEqual(t.Errorf, nil, err) + fmt.Println(rds) } func TestClient_ListDeploySets(t *testing.T) { @@ -391,8 +401,10 @@ func TestClient_CreateRds(t *testing.T) { ZoneName: "cn-su-c", SubnetId: "sbn-8v3p33vhyhq5", }, - }, + DeployId: "", + PoolId: "xdb_gaiabase_pool", + } rds, err := DDC_CLIENT.CreateRds(args) ExpectEqual(t.Errorf, nil, err) diff --git a/services/rds/client_test.go b/services/rds/client_test.go index 943eebfe..7d7d735e 100644 --- a/services/rds/client_test.go +++ b/services/rds/client_test.go @@ -38,7 +38,7 @@ const ( func init() { _, f, _, _ := runtime.Caller(0) - for i := 0; i < 7; i++ { + for i := 0; i < 1; i++ { f = filepath.Dir(f) } conf := filepath.Join(f, "config.json") @@ -129,7 +129,7 @@ func TestClient_ListRds(t *testing.T) { } func TestClient_GetDetail(t *testing.T) { - result, err := RDS_CLIENT.GetDetail(RDS_ID) + result, err := RDS_CLIENT.GetDetail("rds-TTDYFqXr") ExpectEqual(t.Errorf, nil, err) ExpectEqual(t.Errorf, "MySQL", result.Engine) ExpectEqual(t.Errorf, "5.6", result.EngineVersion) @@ -272,7 +272,7 @@ func TestClient_ModifyPublicAccess(t *testing.T) { } func TestClient_GetBackupList(t *testing.T) { - isAvailable(RDS_ID) + isAvailable("rds-ZLlMF0c3") listRdsArgs := &ListRdsArgs{} result, err := RDS_CLIENT.ListRds(listRdsArgs) ExpectEqual(t.Errorf, nil, err) @@ -282,6 +282,7 @@ func TestClient_GetBackupList(t *testing.T) { _, err := RDS_CLIENT.GetBackupList(e.InstanceId, args) ExpectEqual(t.Errorf, nil, err) } + fmt.Println(e) } } @@ -399,4 +400,15 @@ func isAvailable(instanceId string) { break } } -} \ No newline at end of file +} + +func TestClient_AutoRenew(t *testing.T) { + err := RDS_CLIENT.AutoRenew(&AutoRenewArgs{ + AutoRenewTimeUnit: "month", + AutoRenewTime: 1, + InstanceIds: []string{ + "rds-rbmh6gJl", + }, + }) + ExpectEqual(t.Errorf, nil, err) +} diff --git a/services/rds/model.go b/services/rds/model.go index f77200c0..0316d36e 100644 --- a/services/rds/model.go +++ b/services/rds/model.go @@ -119,6 +119,7 @@ type Instance struct { VpcId string `json:"vpcId"` Subnets []Subnet `json:"subnets"` Topology Topology `json:"topology"` + Task string `json:"task"` PaymentTiming string `json:"paymentTiming"` } @@ -218,64 +219,67 @@ type GetBackupListArgs struct { } type GetBackupListResult struct { - Marker string `json:"marker"` - MaxKeys int `json:"maxKeys"` - IsTruncated bool `json:"isTruncated"` - NextMarker string `json:"nextMarker"` - Instances []Instance `json:"instances"` + Marker string `json:"marker"` + MaxKeys int `json:"maxKeys"` + IsTruncated bool `json:"isTruncated"` + NextMarker string `json:"nextMarker"` + Backups []BackupPolicy `json:"backups"` } type GetZoneListResult struct { - Zones []ZoneName `json:"zones"` + Zones []ZoneName `json:"zones"` } type ZoneName struct { - ZoneNames []string `json:"zoneNames"` + ZoneNames []string `json:"zoneNames"` } type ListSubnetsArgs struct { - VpcId string `json:"vpcId"` - ZoneName string `json:"zoneName"` + VpcId string `json:"vpcId"` + ZoneName string `json:"zoneName"` } type ListSubnetsResult struct { - Subnets []Subnet `json:"subnets"` + Subnets []Subnet `json:"subnets"` } type GetSecurityIpsResult struct { - Etag string `json:"etag"` - SecurityIps []string `json:"securityIps"` + Etag string `json:"etag"` + SecurityIps []string `json:"securityIps"` } type UpdateSecurityIpsArgs struct { - SecurityIps []string `json:"securityIps"` + SecurityIps []string `json:"securityIps"` } type ListParametersResult struct { - Etag string `json:"etag"` - Parameters []Parameter `json:"parameters"` + Etag string `json:"etag"` + Parameters []Parameter `json:"parameters"` } type Parameter struct { - Name string `json:"name"` - DefaultValue string `json:"defaultValue"` - Value string `json:"value"` - PendingValue string `json:"pendingValue"` - Type string `json:"type"` - Dynamic string `json:"dynamic"` - Modifiable string `json:"modifiable"` - AllowedValues string `json:"allowedValues"` - Desc string `json:"desc"` + Name string `json:"name"` + DefaultValue string `json:"defaultValue"` + Value string `json:"value"` + PendingValue string `json:"pendingValue"` + Type string `json:"type"` + Dynamic string `json:"dynamic"` + Modifiable string `json:"modifiable"` + AllowedValues string `json:"allowedValues"` + Desc string `json:"desc"` } type UpdateParameterArgs struct { - Parameters []KVParameter `json:"parameters"` + Parameters []KVParameter `json:"parameters"` } type KVParameter struct { - Name string `json:"name"` - Value string `json:"value"` + Name string `json:"name"` + Value string `json:"value"` } - - +type AutoRenewArgs struct { + InstanceIds []string `json:"instanceIds"` + AutoRenewTimeUnit string `json:"autoRenewTimeUnit"` + AutoRenewTime int `json:"autoRenewTime"` +} diff --git a/services/rds/rds.go b/services/rds/rds.go index c10ec1a0..6ecb358f 100644 --- a/services/rds/rds.go +++ b/services/rds/rds.go @@ -527,3 +527,18 @@ func (c *Client) UpdateParameter(instanceId, Etag string, args *UpdateParameterA Do() } +// autoRenew - create autoRenew +// +// PARAMS: +// - Args: *autoRenewArgs +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) AutoRenew(args *AutoRenewArgs) error { + + return bce.NewRequestBuilder(c). + WithMethod(http.PUT). + WithURL(getRdsUri()). + WithQueryParam("autoRenew",""). + WithBody(args). + Do() +}