Skip to content

Commit

Permalink
Add cds' operation in bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Dec 30, 2020
1 parent 8d126b8 commit dfa847e
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 2 deletions.
72 changes: 72 additions & 0 deletions doc/BCC.md
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,47 @@ if err != nil {
> **提示:**
> - 创建CDS磁盘接口为异步接口,可通过[查询磁盘详情](#查询磁盘详情)接口查询磁盘状态,详细接口使用请参考BCC API 文档[查询磁盘详情](https://cloud.baidu.com/doc/BCC/s/1jwvyo4ly)
### 创建CDS磁盘(V3)
支持新建空白CDS磁盘或者从CDS数据盘快照创建CDS磁盘,参考以下代码可以创建CDS磁盘:
```go
// 新建CDS磁盘
args := &api.CreateCDSVolumeV3Args{
// 创建一个CDS磁盘,若要同时创建多个相同配置的磁盘,可以修改此参数
PurchaseCount: 1,
// 磁盘空间大小
VolumeSizeInGB: 50,
// 设置磁盘存储介质
StorageType: api.StorageTypeV3CloudSSDGeneral,
// 设置磁盘付费模式为后付费
Billing: &api.Billing{
PaymentTiming: api.PaymentTimingPostPaid,
},
// 设置磁盘名称
VolumeName: "sdkCreate",
// 设置磁盘描述
Description: "sdk test",
// 快照ID
SnapshotId string "snapshotId",
// 可用区
ZoneName string "zoneName",
// 设置磁盘加密密钥
EncryptKey string "encryptKey",
// 设置自动快照策略id
AutoSnapshotPolicyId string "autoSnapshotPolicyId",
}
result, err := client.CreateCDSVolumeV3(args)
if err != nil {
fmt.Println("create CDS volume failed:", err)
} else {
fmt.Println("create CDS volume success: ", result)
}
```
> **提示:**
> - 创建CDS磁盘接口为异步接口,可通过[查询磁盘详情](#查询磁盘详情)接口查询磁盘状态
### 查询磁盘列表
以下代码可以查询所有的磁盘列表,支持分页查询以及通过次磁盘所挂载的BCC实例id进行过滤筛选:
Expand All @@ -1491,6 +1532,24 @@ if err != nil {
}
```
### 查询磁盘列表(V3)
以下代码可以查询所有的磁盘列表,支持分页查询以及通过次磁盘所挂载的BCC实例id进行过滤筛选:
```go
args := &api.ListCDSVolumeArgs{}

// 设置查询绑定了特定实例的CDS磁盘
args.InstanceId = instanceId

result, err := client.ListCDSVolumeV3(args)
if err != nil {
fmt.Println("list CDS volume failed:", err)
} else {
fmt.Println("list CDS volume success: ", result)
}
```
### 查询磁盘详情
通过磁盘id可以获取对应磁盘的详细信息,以下代码可以查询磁盘详情:
Expand All @@ -1504,6 +1563,19 @@ if err != nil {
}
```
### 查询磁盘详情(V3)
通过磁盘id可以获取对应磁盘的详细信息,以下代码可以查询磁盘详情:
```go
result, err := client.GetCDSVolumeDetailV3(volumeId)
if err != nil {
fmt.Println("get CDS volume detail failed:", err)
} else {
fmt.Println("get CDS volume detail success: ", result.Volume)
}
```
### 挂载CDS磁盘
可以将未挂载的磁盘挂载在对应的BCC虚机下,以下代码将一个CDS挂载在对应的BCC虚机下:
Expand Down
28 changes: 27 additions & 1 deletion doc/VPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,31 @@ fmt.Printf("update vpc %s success.", vpcId)
> 注意: 更新VPC时,对name和description字段的规范要求参考`创建VPC`一节。

## 查询VPC内内网Ip的信息
使用以下代码可以更新指定VPC的名称和描述信息。
>PrivateIpRange的格式为"192.168.0.1-192.168.0-5"
参数中PrivateIpAddresses或PrivateIpRange的ip数量大小不能超过100.
若PrivateIpAddresses和PrivateIpRange同时存在,PrivateIpRange优先。

```go
//import "github.com/baidubce/bce-sdk-go/services/vpc"

args := &GetVpcPrivateIpArgs{
VpcId: "vpc-2pa2x0bjt26i",
PrivateIpAddresses: []string{"192.168.0.1,192.168.0.2"},
PrivateIpRange: "192.168.0.0-192.168.0.45",
}

result, err := client.GetVPCDetail(vpcId)
if err != nil {
fmt.Println("get vpc privateIp address info error: ", err)
return
}


fmt.Println("privateIpAddresses size is : ", len(result.VpcPrivateIpAddresses))

```
# 子网管理

子网是 VPC 内的用户可定义的IP地址范围,根据业务需求,通过CIDR(无类域间路由)可以指定不同的地址空间和IP段。未来用户可以将子网作为一个单位,用来定义Internet访问权限、路由规则和安全策略。
Expand Down Expand Up @@ -1455,7 +1480,8 @@ myLogger.Info("this is my own logger from the VPC go sdk")


# 版本变更记录

## v0.9.6 [2020-12-27]
- 增加vpc查询PrivateIpAddress信息接口
## v0.9.5 [2019-09-24]

首次发布:
Expand Down
12 changes: 12 additions & 0 deletions services/bbc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ func TestGetInstanceEni(t *testing.T) {
}
}

func TestGetInstanceStock(t *testing.T) {
args := &CreateInstanceStockArgs {
FlavorId: "BBC-G4-PDDAS",
ZoneName: "cn-su-a",
}
if res, err := BBC_CLIENT.GetInstanceCreateStock(args); err != nil {
fmt.Println("Get specific instance eni failed: ", err)
} else {
fmt.Println("Get specific instance eni success, result: ", res)
}
}

func TestListRepairTasks(t *testing.T) {
listArgs := &ListRepairTaskArgs{
MaxKeys: 100,
Expand Down
123 changes: 123 additions & 0 deletions services/bcc/api/cds.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ func CreateCDSVolume(cli bce.Client, args *CreateCDSVolumeArgs) (*CreateCDSVolum
return jsonBody, nil
}

// CreateCDSVolumeV3 - create a specified count of cds volumes
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - args: the arguments to create cds volumes
// RETURNS:
// - *CreateCDSVolumeResult: the result of volume ids newly created
// - error: nil if success otherwise the specific error
func CreateCDSVolumeV3(cli bce.Client, args *CreateCDSVolumeV3Args) (*CreateCDSVolumeResult, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getVolumeV3Uri())
req.SetMethod(http.POST)

if args.ClientToken != "" {
req.SetParam("clientToken", args.ClientToken)
}

jsonBytes, err := json.Marshal(args)
if err != nil {
return nil, err
}
body, err := bce.NewBodyFromBytes(jsonBytes)
if err != nil {
return nil, err
}
req.SetBody(body)

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &CreateCDSVolumeResult{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

// ListCDSVolume - list all cds volumes with the given parameters
//
// PARAMS:
Expand Down Expand Up @@ -118,6 +162,55 @@ func ListCDSVolume(cli bce.Client, queryArgs *ListCDSVolumeArgs) (*ListCDSVolume
return jsonBody, nil
}

// ListCDSVolumeV3 - list all cds volumes with the given parameters
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - queryArgs: the optional arguments to list cds volumes
// RETURNS:
// - *ListCDSVolumeResultV3: the result of cds volume list
// - error: nil if success otherwise the specific error
func ListCDSVolumeV3(cli bce.Client, queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResultV3, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getVolumeV3Uri())
req.SetMethod(http.GET)

if queryArgs != nil {
if len(queryArgs.InstanceId) != 0 {
req.SetParam("instanceId", queryArgs.InstanceId)
}
if len(queryArgs.ZoneName) != 0 {
req.SetParam("zoneName", queryArgs.ZoneName)
}
if len(queryArgs.Marker) != 0 {
req.SetParam("marker", queryArgs.Marker)
}
if queryArgs.MaxKeys != 0 {
req.SetParam("maxKeys", strconv.Itoa(queryArgs.MaxKeys))
}
}

if queryArgs == nil || queryArgs.MaxKeys == 0 {
req.SetParam("maxKeys", "1000")
}

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &ListCDSVolumeResultV3{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

// GetCDSVolumeDetail - get details of the specified cds volume
//
// PARAMS:
Expand Down Expand Up @@ -148,6 +241,36 @@ func GetCDSVolumeDetail(cli bce.Client, volumeId string) (*GetVolumeDetailResult
return jsonBody, nil
}

// GetCDSVolumeDetail - get details of the specified cds volume
//
// PARAMS:
// - cli: the client agent which can perform sending request
// - volumeId: id of the cds volume
// RETURNS:
// - *GetVolumeDetailResultV3: the result of the specified cds volume details
// - error: nil if success otherwise the specific error
func GetCDSVolumeDetailV3(cli bce.Client, volumeId string) (*GetVolumeDetailResultV3, error) {
// Build the request
req := &bce.BceRequest{}
req.SetUri(getVolumeV3UriWithId(volumeId))
req.SetMethod(http.GET)

// Send request and get response
resp := &bce.BceResponse{}
if err := cli.SendRequest(req, resp); err != nil {
return nil, err
}
if resp.IsFail() {
return nil, resp.ServiceError()
}

jsonBody := &GetVolumeDetailResultV3{}
if err := resp.ParseJsonBody(jsonBody); err != nil {
return nil, err
}
return jsonBody, nil
}

// AttachCDSVolume - attach an cds volume to a specified instance
//
// PARAMS:
Expand Down
Loading

0 comments on commit dfa847e

Please sign in to comment.