Skip to content

Commit dfa847e

Browse files
committed
Add cds' operation in bcc
1 parent 8d126b8 commit dfa847e

File tree

11 files changed

+471
-2
lines changed

11 files changed

+471
-2
lines changed

doc/BCC.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,47 @@ if err != nil {
14731473
> **提示:**
14741474
> - 创建CDS磁盘接口为异步接口,可通过[查询磁盘详情](#查询磁盘详情)接口查询磁盘状态,详细接口使用请参考BCC API 文档[查询磁盘详情](https://cloud.baidu.com/doc/BCC/s/1jwvyo4ly)
14751475
1476+
### 创建CDS磁盘(V3)
1477+
1478+
支持新建空白CDS磁盘或者从CDS数据盘快照创建CDS磁盘,参考以下代码可以创建CDS磁盘:
1479+
1480+
```go
1481+
// 新建CDS磁盘
1482+
args := &api.CreateCDSVolumeV3Args{
1483+
// 创建一个CDS磁盘,若要同时创建多个相同配置的磁盘,可以修改此参数
1484+
PurchaseCount: 1,
1485+
// 磁盘空间大小
1486+
VolumeSizeInGB: 50,
1487+
// 设置磁盘存储介质
1488+
StorageType: api.StorageTypeV3CloudSSDGeneral,
1489+
// 设置磁盘付费模式为后付费
1490+
Billing: &api.Billing{
1491+
PaymentTiming: api.PaymentTimingPostPaid,
1492+
},
1493+
// 设置磁盘名称
1494+
VolumeName: "sdkCreate",
1495+
// 设置磁盘描述
1496+
Description: "sdk test",
1497+
// 快照ID
1498+
SnapshotId string "snapshotId",
1499+
// 可用区
1500+
ZoneName string "zoneName",
1501+
// 设置磁盘加密密钥
1502+
EncryptKey string "encryptKey",
1503+
// 设置自动快照策略id
1504+
AutoSnapshotPolicyId string "autoSnapshotPolicyId",
1505+
}
1506+
result, err := client.CreateCDSVolumeV3(args)
1507+
if err != nil {
1508+
fmt.Println("create CDS volume failed:", err)
1509+
} else {
1510+
fmt.Println("create CDS volume success: ", result)
1511+
}
1512+
```
1513+
1514+
> **提示:**
1515+
> - 创建CDS磁盘接口为异步接口,可通过[查询磁盘详情](#查询磁盘详情)接口查询磁盘状态
1516+
14761517
### 查询磁盘列表
14771518
14781519
以下代码可以查询所有的磁盘列表,支持分页查询以及通过次磁盘所挂载的BCC实例id进行过滤筛选:
@@ -1491,6 +1532,24 @@ if err != nil {
14911532
}
14921533
```
14931534
1535+
### 查询磁盘列表(V3)
1536+
1537+
以下代码可以查询所有的磁盘列表,支持分页查询以及通过次磁盘所挂载的BCC实例id进行过滤筛选:
1538+
1539+
```go
1540+
args := &api.ListCDSVolumeArgs{}
1541+
1542+
// 设置查询绑定了特定实例的CDS磁盘
1543+
args.InstanceId = instanceId
1544+
1545+
result, err := client.ListCDSVolumeV3(args)
1546+
if err != nil {
1547+
fmt.Println("list CDS volume failed:", err)
1548+
} else {
1549+
fmt.Println("list CDS volume success: ", result)
1550+
}
1551+
```
1552+
14941553
### 查询磁盘详情
14951554
14961555
通过磁盘id可以获取对应磁盘的详细信息,以下代码可以查询磁盘详情:
@@ -1504,6 +1563,19 @@ if err != nil {
15041563
}
15051564
```
15061565
1566+
### 查询磁盘详情(V3)
1567+
1568+
通过磁盘id可以获取对应磁盘的详细信息,以下代码可以查询磁盘详情:
1569+
1570+
```go
1571+
result, err := client.GetCDSVolumeDetailV3(volumeId)
1572+
if err != nil {
1573+
fmt.Println("get CDS volume detail failed:", err)
1574+
} else {
1575+
fmt.Println("get CDS volume detail success: ", result.Volume)
1576+
}
1577+
```
1578+
15071579
### 挂载CDS磁盘
15081580
15091581
可以将未挂载的磁盘挂载在对应的BCC虚机下,以下代码将一个CDS挂载在对应的BCC虚机下:

doc/VPC.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,31 @@ fmt.Printf("update vpc %s success.", vpcId)
377377
> 注意: 更新VPC时,对name和description字段的规范要求参考`创建VPC`一节。
378378
379379

380+
## 查询VPC内内网Ip的信息
381+
使用以下代码可以更新指定VPC的名称和描述信息。
382+
>PrivateIpRange的格式为"192.168.0.1-192.168.0-5"
383+
参数中PrivateIpAddresses或PrivateIpRange的ip数量大小不能超过100.
384+
若PrivateIpAddresses和PrivateIpRange同时存在,PrivateIpRange优先。
385+
386+
```go
387+
//import "github.com/baidubce/bce-sdk-go/services/vpc"
388+
389+
args := &GetVpcPrivateIpArgs{
390+
VpcId: "vpc-2pa2x0bjt26i",
391+
PrivateIpAddresses: []string{"192.168.0.1,192.168.0.2"},
392+
PrivateIpRange: "192.168.0.0-192.168.0.45",
393+
}
394+
395+
result, err := client.GetVPCDetail(vpcId)
396+
if err != nil {
397+
fmt.Println("get vpc privateIp address info error: ", err)
398+
return
399+
}
400+
401+
402+
fmt.Println("privateIpAddresses size is : ", len(result.VpcPrivateIpAddresses))
403+
404+
```
380405
# 子网管理
381406

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

14561481

14571482
# 版本变更记录
1458-
1483+
## v0.9.6 [2020-12-27]
1484+
- 增加vpc查询PrivateIpAddress信息接口
14591485
## v0.9.5 [2019-09-24]
14601486

14611487
首次发布:

services/bbc/client_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,18 @@ func TestGetInstanceEni(t *testing.T) {
479479
}
480480
}
481481

482+
func TestGetInstanceStock(t *testing.T) {
483+
args := &CreateInstanceStockArgs {
484+
FlavorId: "BBC-G4-PDDAS",
485+
ZoneName: "cn-su-a",
486+
}
487+
if res, err := BBC_CLIENT.GetInstanceCreateStock(args); err != nil {
488+
fmt.Println("Get specific instance eni failed: ", err)
489+
} else {
490+
fmt.Println("Get specific instance eni success, result: ", res)
491+
}
492+
}
493+
482494
func TestListRepairTasks(t *testing.T) {
483495
listArgs := &ListRepairTaskArgs{
484496
MaxKeys: 100,

services/bcc/api/cds.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ func CreateCDSVolume(cli bce.Client, args *CreateCDSVolumeArgs) (*CreateCDSVolum
6969
return jsonBody, nil
7070
}
7171

72+
// CreateCDSVolumeV3 - create a specified count of cds volumes
73+
//
74+
// PARAMS:
75+
// - cli: the client agent which can perform sending request
76+
// - args: the arguments to create cds volumes
77+
// RETURNS:
78+
// - *CreateCDSVolumeResult: the result of volume ids newly created
79+
// - error: nil if success otherwise the specific error
80+
func CreateCDSVolumeV3(cli bce.Client, args *CreateCDSVolumeV3Args) (*CreateCDSVolumeResult, error) {
81+
// Build the request
82+
req := &bce.BceRequest{}
83+
req.SetUri(getVolumeV3Uri())
84+
req.SetMethod(http.POST)
85+
86+
if args.ClientToken != "" {
87+
req.SetParam("clientToken", args.ClientToken)
88+
}
89+
90+
jsonBytes, err := json.Marshal(args)
91+
if err != nil {
92+
return nil, err
93+
}
94+
body, err := bce.NewBodyFromBytes(jsonBytes)
95+
if err != nil {
96+
return nil, err
97+
}
98+
req.SetBody(body)
99+
100+
// Send request and get response
101+
resp := &bce.BceResponse{}
102+
if err := cli.SendRequest(req, resp); err != nil {
103+
return nil, err
104+
}
105+
if resp.IsFail() {
106+
return nil, resp.ServiceError()
107+
}
108+
109+
jsonBody := &CreateCDSVolumeResult{}
110+
if err := resp.ParseJsonBody(jsonBody); err != nil {
111+
return nil, err
112+
}
113+
return jsonBody, nil
114+
}
115+
72116
// ListCDSVolume - list all cds volumes with the given parameters
73117
//
74118
// PARAMS:
@@ -118,6 +162,55 @@ func ListCDSVolume(cli bce.Client, queryArgs *ListCDSVolumeArgs) (*ListCDSVolume
118162
return jsonBody, nil
119163
}
120164

165+
// ListCDSVolumeV3 - list all cds volumes with the given parameters
166+
//
167+
// PARAMS:
168+
// - cli: the client agent which can perform sending request
169+
// - queryArgs: the optional arguments to list cds volumes
170+
// RETURNS:
171+
// - *ListCDSVolumeResultV3: the result of cds volume list
172+
// - error: nil if success otherwise the specific error
173+
func ListCDSVolumeV3(cli bce.Client, queryArgs *ListCDSVolumeArgs) (*ListCDSVolumeResultV3, error) {
174+
// Build the request
175+
req := &bce.BceRequest{}
176+
req.SetUri(getVolumeV3Uri())
177+
req.SetMethod(http.GET)
178+
179+
if queryArgs != nil {
180+
if len(queryArgs.InstanceId) != 0 {
181+
req.SetParam("instanceId", queryArgs.InstanceId)
182+
}
183+
if len(queryArgs.ZoneName) != 0 {
184+
req.SetParam("zoneName", queryArgs.ZoneName)
185+
}
186+
if len(queryArgs.Marker) != 0 {
187+
req.SetParam("marker", queryArgs.Marker)
188+
}
189+
if queryArgs.MaxKeys != 0 {
190+
req.SetParam("maxKeys", strconv.Itoa(queryArgs.MaxKeys))
191+
}
192+
}
193+
194+
if queryArgs == nil || queryArgs.MaxKeys == 0 {
195+
req.SetParam("maxKeys", "1000")
196+
}
197+
198+
// Send request and get response
199+
resp := &bce.BceResponse{}
200+
if err := cli.SendRequest(req, resp); err != nil {
201+
return nil, err
202+
}
203+
if resp.IsFail() {
204+
return nil, resp.ServiceError()
205+
}
206+
207+
jsonBody := &ListCDSVolumeResultV3{}
208+
if err := resp.ParseJsonBody(jsonBody); err != nil {
209+
return nil, err
210+
}
211+
return jsonBody, nil
212+
}
213+
121214
// GetCDSVolumeDetail - get details of the specified cds volume
122215
//
123216
// PARAMS:
@@ -148,6 +241,36 @@ func GetCDSVolumeDetail(cli bce.Client, volumeId string) (*GetVolumeDetailResult
148241
return jsonBody, nil
149242
}
150243

244+
// GetCDSVolumeDetail - get details of the specified cds volume
245+
//
246+
// PARAMS:
247+
// - cli: the client agent which can perform sending request
248+
// - volumeId: id of the cds volume
249+
// RETURNS:
250+
// - *GetVolumeDetailResultV3: the result of the specified cds volume details
251+
// - error: nil if success otherwise the specific error
252+
func GetCDSVolumeDetailV3(cli bce.Client, volumeId string) (*GetVolumeDetailResultV3, error) {
253+
// Build the request
254+
req := &bce.BceRequest{}
255+
req.SetUri(getVolumeV3UriWithId(volumeId))
256+
req.SetMethod(http.GET)
257+
258+
// Send request and get response
259+
resp := &bce.BceResponse{}
260+
if err := cli.SendRequest(req, resp); err != nil {
261+
return nil, err
262+
}
263+
if resp.IsFail() {
264+
return nil, resp.ServiceError()
265+
}
266+
267+
jsonBody := &GetVolumeDetailResultV3{}
268+
if err := resp.ParseJsonBody(jsonBody); err != nil {
269+
return nil, err
270+
}
271+
return jsonBody, nil
272+
}
273+
151274
// AttachCDSVolume - attach an cds volume to a specified instance
152275
//
153276
// PARAMS:

0 commit comments

Comments
 (0)