Skip to content

Commit

Permalink
Update features in bcc and bls
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Nov 29, 2024
1 parent 65afb20 commit 570958b
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 62 deletions.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 20 additions & 0 deletions doc/BCC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
```
### 删除快照
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions services/bcc/api/cds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


110 changes: 68 additions & 42 deletions services/bcc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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"`
}
6 changes: 6 additions & 0 deletions services/bcc/api/other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions services/bcc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 16 additions & 1 deletion services/bcc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ func TestCreateSnapshot(t *testing.T) {
TagValue: "val",
},
},
RetentionInDays: 1,
}
result, err := BCC_CLIENT.CreateSnapshot(args)
ExpectEqual(t.Errorf, err, nil)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

15 changes: 11 additions & 4 deletions services/bls/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions services/bls/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 570958b

Please sign in to comment.