diff --git a/bce/config.go b/bce/config.go index a6cb50d1..243b4c81 100644 --- a/bce/config.go +++ b/bce/config.go @@ -26,7 +26,7 @@ import ( // Constants and default values for the package bce const ( - SDK_VERSION = "0.9.201" + SDK_VERSION = "0.9.202" URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path DEFAULT_DOMAIN = "baidubce.com" DEFAULT_PROTOCOL = "http" diff --git a/doc/BCC.md b/doc/BCC.md index c7bc6a2d..2ba0ac88 100644 --- a/doc/BCC.md +++ b/doc/BCC.md @@ -2763,6 +2763,7 @@ args := &api.CreateSnapshotArgs{ VolumeId: volumeId, SnapshotName: "sdk", Description: "create by sdk", + RetentionInDays: 1, } result, err := client.CreateSnapshot(args) if err != nil { @@ -2796,6 +2797,22 @@ if err != nil { fmt.Println("get snapshot detail success: ", result) } ``` +### 修改快照属性 + +如下代码可以修改快照属性 +```go +args := &api.ModifySnapshotAttributeArgs{ +SnapshotName: "test-snapshot", +Desc: "test-desc", +RetentionInDays: 1, +} +err := client.ModifySnapshotAttribute(snapshotId, args) +if err != nil { + fmt.Println("modify snapshot attribute failed:", err) +} else { + fmt.Println("modify snapshot attribute success") +} +``` ### 删除快照 @@ -3431,8 +3448,11 @@ if err != nil { ```go // 设置可用区名称,可选 zoneName := "your-zone-name" +// 设置套餐,可选 +specs := "spec1,spec2" args := &api.ListFlavorSpecArgs{ ZoneName: zoneName, + Specs: specs, } if res, err := bccClient.ListFlavorSpec(args); err != nil { fmt.Println("Get specified flavor list failed: ", err) diff --git a/services/bcc/api/cds.go b/services/bcc/api/cds.go index 4257827e..d889f9a2 100644 --- a/services/bcc/api/cds.go +++ b/services/bcc/api/cds.go @@ -934,3 +934,35 @@ func GetCdsPrice(cli bce.Client, args *VolumePriceRequestArgs) (*VolumePriceResp return jsonBody, nil } +func ModifySnapshotAttribute(cli bce.Client, snapshotId string, args *ModifySnapshotAttributeArgs) error { + // Build the request + req := &bce.BceRequest{} + req.SetUri(getSnapshotUriWithId(snapshotId)) + req.SetMethod(http.PUT) + + req.SetParam("modifyAttribute", "") + + jsonBytes, err := json.Marshal(args) + if err != nil { + return err + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return err + } + req.SetBody(body) + + // Send request and get response + resp := &bce.BceResponse{} + if err := cli.SendRequest(req, resp); err != nil { + return err + } + if resp.IsFail() { + return resp.ServiceError() + } + + defer func() { resp.Body().Close() }() + return nil +} + + diff --git a/services/bcc/api/model.go b/services/bcc/api/model.go index 9b57ca39..c2249962 100644 --- a/services/bcc/api/model.go +++ b/services/bcc/api/model.go @@ -1741,11 +1741,12 @@ type GetImageOsArgs struct { } type CreateSnapshotArgs struct { - ClientToken string `json:"-"` - VolumeId string `json:"volumeId"` - SnapshotName string `json:"snapshotName"` - Description string `json:"desc,omitempty"` - Tags []model.TagModel `json:"tags"` + ClientToken string `json:"-"` + VolumeId string `json:"volumeId"` + SnapshotName string `json:"snapshotName"` + Description string `json:"desc,omitempty"` + Tags []model.TagModel `json:"tags"` + RetentionInDays int `json:"retentionInDays,omitempty"` } type CreateSnapshotResult struct { @@ -2047,6 +2048,8 @@ type CreateBidInstanceResult struct { type ListFlavorSpecArgs struct { ZoneName string `json:"zoneName,omitempty"` + Specs string `json:"specs,omitempty"` + SpecIds string `json:"specIds,omitempty"` } type ListFlavorSpecResult struct { @@ -2069,26 +2072,34 @@ type FlavorGroup struct { } type BccFlavor struct { - CpuCount int `json:"cpuCount"` - MemoryCapacityInGB int `json:"memoryCapacityInGB"` - EphemeralDiskInGb int `json:"ephemeralDiskInGb"` - EphemeralDiskCount int `json:"ephemeralDiskCount"` - EphemeralDiskType string `json:"ephemeralDiskType"` - GpuCardType string `json:"gpuCardType"` - GpuCardCount int `json:"gpuCardCount"` - FpgaCardType string `json:"fpgaCardType"` - FpgaCardCount int `json:"fpgaCardCount"` - ProductType string `json:"productType"` - Spec string `json:"spec"` - SpecId string `json:"specId"` - FlavorSubType string `json:"flavorSubType"` - CpuModel string `json:"cpuModel"` - CpuGHz string `json:"cpuGHz"` - NetworkBandwidth string `json:"networkBandwidth"` - NetworkPackage string `json:"networkPackage"` - NetEthQueueCount string `json:"netEthQueueCount"` - EnableJumboFrame bool `json:"enableJumboFrame"` - NetEthMaxQueueCount string `json:"netEthMaxQueueCount"` + CpuCount int `json:"cpuCount"` + MemoryCapacityInGB int `json:"memoryCapacityInGB"` + EphemeralDiskInGb int `json:"ephemeralDiskInGb"` + EphemeralDiskCount int `json:"ephemeralDiskCount"` + EphemeralDiskType string `json:"ephemeralDiskType"` + GpuCardType string `json:"gpuCardType"` + GpuCardCount int `json:"gpuCardCount"` + FpgaCardType string `json:"fpgaCardType"` + FpgaCardCount int `json:"fpgaCardCount"` + ProductType string `json:"productType"` + Spec string `json:"spec"` + SpecId string `json:"specId"` + FlavorSubType string `json:"flavorSubType"` + CpuModel string `json:"cpuModel"` + CpuGHz string `json:"cpuGHz"` + NetworkBandwidth string `json:"networkBandwidth"` + NetworkPackage string `json:"networkPackage"` + NetEthQueueCount string `json:"netEthQueueCount"` + EnableJumboFrame bool `json:"enableJumboFrame"` + NicIpv4Quota int `json:"nicIpv4Quota"` + NicIpv6Quota int `json:"nicIpv6Quota"` + EniQuota int `json:"eniQuota"` + EriQuota int `json:"eriQuota"` + RdmaType string `json:"rdmaType"` + RdmaNetCardCount int `json:"rdmaNetCardCount"` + RdmaNetBandwidth int `json:"rdmaNetBandwidth"` + SystemDiskType []string `json:"systemDiskType"` + DataDiskType []string `json:"dataDiskType"` } type EbcResources struct { @@ -2101,23 +2112,32 @@ type EbcFlavorGroup struct { } type EbcFlavor struct { - CpuCount int `json:"cpuCount"` - MemoryCapacityInGB int `json:"memoryCapacityInGB"` - EphemeralDiskInGb int `json:"ephemeralDiskInGb"` - EphemeralDiskCount string `json:"ephemeralDiskCount"` - EphemeralDiskType string `json:"ephemeralDiskType"` - GpuCardType string `json:"gpuCardType"` - GpuCardCount string `json:"gpuCardCount"` - FpgaCardType string `json:"fpgaCardType"` - FpgaCardCount string `json:"fpgaCardCount"` - ProductType string `json:"productType"` - Spec string `json:"spec"` - SpecId string `json:"specId"` - FlavorSubType string `json:"flavorSubType"` - CpuModel string `json:"cpuModel"` - CpuGHz string `json:"cpuGHz"` - NetworkBandwidth string `json:"networkBandwidth"` - NetworkPackage string `json:"networkPackage"` + CpuCount int `json:"cpuCount"` + MemoryCapacityInGB int `json:"memoryCapacityInGB"` + EphemeralDiskInGb int `json:"ephemeralDiskInGb"` + EphemeralDiskCount string `json:"ephemeralDiskCount"` + EphemeralDiskType string `json:"ephemeralDiskType"` + GpuCardType string `json:"gpuCardType"` + GpuCardCount string `json:"gpuCardCount"` + FpgaCardType string `json:"fpgaCardType"` + FpgaCardCount string `json:"fpgaCardCount"` + ProductType string `json:"productType"` + Spec string `json:"spec"` + SpecId string `json:"specId"` + FlavorSubType string `json:"flavorSubType"` + CpuModel string `json:"cpuModel"` + CpuGHz string `json:"cpuGHz"` + NetworkBandwidth string `json:"networkBandwidth"` + NetworkPackage string `json:"networkPackage"` + NicIpv4Quota int `json:"nicIpv4Quota"` + NicIpv6Quota int `json:"nicIpv6Quota"` + EniQuota int `json:"eniQuota"` + EriQuota int `json:"eriQuota"` + RdmaType string `json:"rdmaType"` + RdmaNetCardCount int `json:"rdmaNetCardCount"` + RdmaNetBandwidth int `json:"rdmaNetBandwidth"` + SystemDiskType []string `json:"systemDiskType"` + DataDiskType []string `json:"dataDiskType"` } type GetPriceBySpecArgs struct { @@ -2710,3 +2730,9 @@ type EhcCluster struct { InstanceIds []string `json:"instanceIds"` ReservedInstanceIds []string `json:"reservedInstanceIds"` } + +type ModifySnapshotAttributeArgs struct { + SnapshotName string `json:"snapshotName,omitempty"` + Desc string `json:"desc,omitempty"` + RetentionInDays int `json:"retentionInDays,omitempty"` +} diff --git a/services/bcc/api/other.go b/services/bcc/api/other.go index bb21456e..f90869f9 100644 --- a/services/bcc/api/other.go +++ b/services/bcc/api/other.go @@ -101,6 +101,12 @@ func ListFlavorSpec(cli bce.Client, args *ListFlavorSpecArgs) (*ListFlavorSpecRe if len(args.ZoneName) != 0 { req.SetParam("zoneName", args.ZoneName) } + if len(args.Specs) != 0 { + req.SetParam("specs", args.Specs) + } + if len(args.SpecIds) != 0 { + req.SetParam("specIds", args.SpecIds) + } } // Send request and get response diff --git a/services/bcc/client.go b/services/bcc/client.go index b4819525..d5d1e7e5 100644 --- a/services/bcc/client.go +++ b/services/bcc/client.go @@ -2640,3 +2640,16 @@ func (c *Client) DeleteEhcCluster(args *api.DeleteEhcClusterArg) error { func (c *Client) GetSecurityGroupDetail(securityGroupId string) (*api.GetSecurityGroupDetailResult, error) { return api.GetSecurityGroupDetail(c, securityGroupId) } + +// ModifySnapshotAttribute - modify snapshot attribute +// +// PARAMS: +// - cli: the client agent which can perform sending request +// - snapshotId: the id of snapshot +// - args: the arguments of method +// +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) ModifySnapshotAttribute(snapshotId string, args *api.ModifySnapshotAttributeArgs) error { + return api.ModifySnapshotAttribute(c, snapshotId, args) +} diff --git a/services/bcc/client_test.go b/services/bcc/client_test.go index d8e13236..022cf03b 100644 --- a/services/bcc/client_test.go +++ b/services/bcc/client_test.go @@ -544,6 +544,7 @@ func TestCreateSnapshot(t *testing.T) { TagValue: "val", }, }, + RetentionInDays: 1, } result, err := BCC_CLIENT.CreateSnapshot(args) ExpectEqual(t.Errorf, err, nil) @@ -959,7 +960,10 @@ func TestListZone(t *testing.T) { } func TestListFlavorSpec(t *testing.T) { - args := &api.ListFlavorSpecArgs{} + args := &api.ListFlavorSpecArgs{ + Specs: "bcc.g5.c2m8", + ZoneName: "cn-bj-b", + } res, err := BCC_CLIENT.ListFlavorSpec(args) ExpectEqual(t.Errorf, err, nil) // fmt.Println(res.ZoneResources[0].BccResources.FlavorGroups[0].Flavors[0].NetEthQueueCount) @@ -2240,3 +2244,14 @@ func TestClient_GetSecurityDetail(t *testing.T) { ExpectEqual(t.Errorf, err, nil) fmt.Println(res) } + +func TestModifySnapshotAttribute(t *testing.T) { + args := &api.ModifySnapshotAttributeArgs{ + SnapshotName: "test-snapshot", + Desc: "test-desc", + RetentionInDays: 1, + } + err := BCC_CLIENT.ModifySnapshotAttribute("s-Dzmlx7Fz", args) + ExpectEqual(t.Errorf, err, nil) +} + diff --git a/services/bls/api/model.go b/services/bls/api/model.go index eef16ddc..3dee15d2 100644 --- a/services/bls/api/model.go +++ b/services/bls/api/model.go @@ -217,13 +217,20 @@ type ListFastQueryResult struct { } type LogField struct { - Type string `json:"type"` - Fields map[string]LogField `json:"fields,omitempty"` + Type string `json:"type"` + CaseSensitive bool `json:"caseSensitive"` + Separators string `json:"separators"` + IncludeChinese bool `json:"includeChinese"` + Fields map[string]LogField `json:"fields,omitempty"` + DynamicMapping bool `json:"dynamicMapping,omitempty"` } type IndexFields struct { - FullText bool `json:"fulltext"` - Fields map[string]LogField `json:"fields"` + FullText bool `json:"fulltext"` + CaseSensitive bool `json:"caseSensitive"` + Separators string `json:"separators"` + IncludeChinese bool `json:"includeChinese"` + Fields map[string]LogField `json:"fields"` } type CreateLogShipperBody struct { diff --git a/services/bls/client_v2.go b/services/bls/client_v2.go index 2fa3349e..5360143d 100644 --- a/services/bls/client_v2.go +++ b/services/bls/client_v2.go @@ -197,8 +197,11 @@ func (c *Client) ListFastQueryV2(request ListFastQueryRequest) (*api.ListFastQue func (c *Client) CreateIndexV2(request CreateIndexRequest) error { params, jsonErr := json.Marshal(&api.IndexFields{ - FullText: request.Fulltext, - Fields: request.Fields, + FullText: request.Fulltext, + Fields: request.Fields, + CaseSensitive: request.CaseSensitive, + IncludeChinese: request.IncludeChinese, + Separators: request.Separators, }) if jsonErr != nil { return jsonErr @@ -212,8 +215,11 @@ func (c *Client) CreateIndexV2(request CreateIndexRequest) error { func (c *Client) UpdateIndexV2(request UpdateIndexRequest) error { params, jsonErr := json.Marshal(&api.IndexFields{ - FullText: request.Fulltext, - Fields: request.Fields, + FullText: request.Fulltext, + Fields: request.Fields, + CaseSensitive: request.CaseSensitive, + IncludeChinese: request.IncludeChinese, + Separators: request.Separators, }) if jsonErr != nil { return jsonErr diff --git a/services/bls/client_v2_test.go b/services/bls/client_v2_test.go index 426f7651..d0411d99 100644 --- a/services/bls/client_v2_test.go +++ b/services/bls/client_v2_test.go @@ -1,6 +1,7 @@ package bls import ( + "strings" "testing" "time" @@ -64,28 +65,58 @@ func TestLogStoreAndIndexV2(t *testing.T) { // test index api createIndexRequest := CreateIndexRequest{ - Project: createLogStoreRequest.Project, - LogStoreName: createLogStoreRequest.LogStoreName, - Fulltext: true, + Project: createLogStoreRequest.Project, + LogStoreName: createLogStoreRequest.LogStoreName, + Fulltext: true, + CaseSensitive: true, + Separators: "", + IncludeChinese: true, Fields: map[string]api.LogField{ "test1": { - Type: "float", + Type: "float", + CaseSensitive: true, + Separators: "", + IncludeChinese: true, }, }, } err = BLS_CLIENT.CreateIndexV2(createIndexRequest) ExpectEqual(t.Errorf, err, nil) + idx, err := BLS_CLIENT.DescribeIndexV2(DescribeIndexRequest{ + Project: createIndexRequest.Project, + LogStoreName: createIndexRequest.LogStoreName, + }) + ExpectEqual(t.Errorf, err, nil) + ExpectEqual(t.Errorf, true, idx.FullText) + ExpectEqual(t.Errorf, true, idx.CaseSensitive) + ExpectEqual(t.Errorf, true, idx.IncludeChinese) + ExpectEqual(t.Errorf, "@&?|#()='\",;:<>[]{}/ \n\t\r\\", idx.Separators) + ExpectEqual(t.Errorf, 1, len(idx.Fields)) + ExpectEqual(t.Errorf, "float", idx.Fields["test1"].Type) + ExpectEqual(t.Errorf, true, idx.Fields["test1"].CaseSensitive) + ExpectEqual(t.Errorf, true, idx.Fields["test1"].IncludeChinese) + ExpectEqual(t.Errorf, "@&?|#()='\",;:<>[]{}/ \n\t\r\\", idx.Fields["test1"].Separators) updateIndexRequest := UpdateIndexRequest{ - Project: createLogStoreRequest.Project, - LogStoreName: createLogStoreRequest.LogStoreName, - Fulltext: true, + Project: createLogStoreRequest.Project, + LogStoreName: createLogStoreRequest.LogStoreName, + Fulltext: true, + CaseSensitive: false, + IncludeChinese: true, + Separators: "@&?", + Fields: map[string]api.LogField{ "test1": { - Type: "float", + Type: "float", + CaseSensitive: true, + Separators: "@?", + IncludeChinese: false, }, "test2": { - Type: "bool", + Type: "bool", + CaseSensitive: true, + Separators: "", + IncludeChinese: false, }, }, } @@ -96,12 +127,25 @@ func TestLogStoreAndIndexV2(t *testing.T) { Project: createLogStoreRequest.Project, LogStoreName: createLogStoreRequest.LogStoreName, } - idx, err := BLS_CLIENT.DescribeIndexV2(describeIndexRequest) + idx, err = BLS_CLIENT.DescribeIndexV2(describeIndexRequest) ExpectEqual(t.Errorf, err, nil) ExpectEqual(t.Errorf, true, idx.FullText) + ExpectEqual(t.Errorf, false, idx.CaseSensitive) + ExpectEqual(t.Errorf, true, idx.IncludeChinese) + ExpectEqual(t.Errorf, 3, len(idx.Separators)) + ExpectEqual(t.Errorf, true, strings.Contains(idx.Separators, "@") && strings.Contains(idx.Separators, "?") && + strings.Contains(idx.Separators, "&")) ExpectEqual(t.Errorf, 2, len(idx.Fields)) ExpectEqual(t.Errorf, "float", idx.Fields["test1"].Type) + ExpectEqual(t.Errorf, true, idx.Fields["test1"].CaseSensitive) + ExpectEqual(t.Errorf, false, idx.Fields["test1"].IncludeChinese) + ExpectEqual(t.Errorf, 2, len(idx.Fields["test1"].Separators)) + ExpectEqual(t.Errorf, true, strings.Contains(idx.Fields["test1"].Separators, "@") && + strings.Contains(idx.Fields["test1"].Separators, "?")) ExpectEqual(t.Errorf, "bool", idx.Fields["test2"].Type) + ExpectEqual(t.Errorf, true, idx.Fields["test2"].CaseSensitive) + ExpectEqual(t.Errorf, false, idx.Fields["test2"].IncludeChinese) + ExpectEqual(t.Errorf, "@&?|#()='\",;:<>[]{}/ \n\t\r\\", idx.Fields["test2"].Separators) deleteIndexRequest := DeleteIndexRequest{ Project: createLogStoreRequest.Project, diff --git a/services/bls/model.go b/services/bls/model.go index 65036d64..3e0720ef 100644 --- a/services/bls/model.go +++ b/services/bls/model.go @@ -239,6 +239,12 @@ type CreateIndexRequest struct { LogStoreName string `json:"logStoreName"` // 是否开启全文索引,默认false,不开启全文索引 Fulltext bool `json:"fulltext"` + // 全文索引是否开启大小写敏感,默认false,不开启大小写敏感 + CaseSensitive bool `json:"caseSensitive"` + // 全文分词符,将字段内容按照分词符拆分成若干个分词用于检索 + Separators string `json:"separators"` + // 是否包含中文,默认为false,不包含中文 + IncludeChinese bool `json:"includeChinese"` // 字段索引信息 Fields map[string]api.LogField `json:"fields"` } @@ -250,6 +256,12 @@ type UpdateIndexRequest struct { LogStoreName string `json:"logStoreName"` // 是否开启全文索引,默认false,不开启全文索引 Fulltext bool `json:"fulltext"` + // 全文索引是否开启大小写敏感,默认false,不开启大小写敏感 + CaseSensitive bool `json:"caseSensitive"` + // 全文分词符,将字段内容按照分词符拆分成若干个分词用于检索 + Separators string `json:"separators"` + // 是否包含中文,默认为false,不包含中文 + IncludeChinese bool `json:"includeChinese"` // 字段索引信息 Fields map[string]api.LogField `json:"fields"` }