Skip to content

Commit 9125be3

Browse files
committed
Add features in bcc and nat
1 parent 868bf01 commit 9125be3

File tree

10 files changed

+143
-0
lines changed

10 files changed

+143
-0
lines changed

Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
发行说明:记录每次SDK更新的说明,最新版本的SDK包含以前所有版本的更新内容。
22
---------------------------------------------------------------------
3+
【版本:v0.9.217】
4+
涉及产品:BCC
5+
创建实例支持CDS加密
6+
涉及产品:NAT
7+
支持增强型NAT
38
【版本:v0.9.216】
49
涉及产品:HPAS
510
修改创建券、查询券、查询镜像列表等接口的参数命名

examples/vpc/nat/example_create_nat.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func CreateNat() {
2424
Eips: []string{},
2525
// 设置nat网关的dnat eip列表
2626
DnatEips: []string{},
27+
// 设置nat网关的bind eip列表
28+
BindEips: []string{},
2729
// 设置nat绑定的资源组ID,此字段选传,传则表示绑定资源组
2830
ResourceGroupId: "ResourceGroupId",
2931
// 设置nat网关的计费信息
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package vpcexamples
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/baidubce/bce-sdk-go/services/vpc"
7+
)
8+
9+
// 以下为示例代码,实际开发中请根据需要进行修改和补充
10+
11+
func EnhanceNatBindEip() {
12+
ak, sk, endpoint := "Your AK", "Your SK", "bcc.bj.baidubce.com"
13+
14+
natClient, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
15+
16+
NatID := "Your nat's id"
17+
18+
args := &vpc.EnhanceNatBindEipsArgs{
19+
// 设置要绑定的 EIP 列表
20+
BindEips: []string{"180.76.186.174"}, // 替换为需要绑定的 EIP 列表
21+
}
22+
if err := natClient.EnhanceNatBindEips(NatID, args); err != nil {
23+
fmt.Println("bind eips error: ", err)
24+
return
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package vpcexamples
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/baidubce/bce-sdk-go/services/vpc"
7+
)
8+
9+
// 以下为示例代码,实际开发中请根据需要进行修改和补充
10+
11+
func EnhanceNatUnBindEip() {
12+
ak, sk, endpoint := "Your AK", "Your SK", "bcc.bj.baidubce.com"
13+
14+
natClient, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
15+
16+
NatID := "Your nat's id"
17+
18+
args := &vpc.EnhanceNatUnBindEipsArgs{
19+
// 设置要解绑的 EIP 列表
20+
BindEips: []string{"180.76.186.174"}, // 替换为需要解绑的 EIP 列表
21+
}
22+
if err := natClient.EnhanceNatUnBindEips(NatID, args); err != nil {
23+
fmt.Println("unbind eips error: ", err)
24+
return
25+
}
26+
}

examples/vpc/nat/example_get_nat_detail.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ func GetNatDetail() {
2727
fmt.Println("nat name: ", result.Name)
2828
// 查询得到nat网关所属的vpc id
2929
fmt.Println("nat vpcId: ", result.VpcId)
30+
// 查询得到nat网关类型,增强型或者普通型
31+
fmt.Println("nat type: ", result.NatType)
3032
// 查询得到nat网关的大小
3133
fmt.Println("nat spec: ", result.Spec)
3234
// 查询得到nat网关绑定的snat EIP的IP地址列表
3335
fmt.Println("nat snat eips: ", result.Eips)
3436
// 查询得到nat网关绑定的dnat EIP的IP地址列表
3537
fmt.Println("nat dnat eips: ", result.DnatEips)
38+
// 查询得到增强型nat网关绑定的bind EIP的IP地址列表
39+
fmt.Println("nat bind eips: ", result.BindEips)
3640
// 查询得到nat网关的状态
3741
fmt.Println("nat status: ", result.Status)
3842
// 查询得到nat网关的付费方式

examples/vpc/nat/example_list_nat.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func ListNat() {
3030
fmt.Println("nat id: ", nat.Id)
3131
fmt.Println("nat name: ", nat.Name)
3232
fmt.Println("nat vpcId: ", nat.VpcId)
33+
fmt.Println("nat type: ", nat.NatType)
3334
fmt.Println("nat spec: ", nat.Spec)
3435
fmt.Println("nat snat eips: ", nat.Eips)
3536
fmt.Println("nat dnat eips: ", nat.DnatEips)
37+
fmt.Println("nat bind eips: ", nat.BindEips)
3638
fmt.Println("nat status: ", nat.Status)
3739
fmt.Println("nat paymentTiming: ", nat.PaymentTiming)
3840
fmt.Println("nat expireTime: ", nat.ExpiredTime)

services/bcc/api/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,14 @@ type CreateCdsModel struct {
278278
CdsSizeInGB int `json:"cdsSizeInGB"`
279279
StorageType StorageType `json:"storageType"`
280280
SnapShotId string `json:"snapshotId,omitempty"`
281+
EncryptKey string `json:"encryptKey,omitempty"`
281282
}
282283

283284
type CreateCdsModelV3 struct {
284285
CdsSizeInGB int `json:"cdsSizeInGB"`
285286
StorageType StorageTypeV3 `json:"storageType"`
286287
SnapShotId string `json:"snapshotId,omitempty"`
288+
EncryptKey string `json:"encryptKey,omitempty"`
287289
}
288290

289291
type DiskInfo struct {

services/vpc/client_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ func TestCreateEnhanceNatGateway(t *testing.T) {
405405
Name: "Test-SDK-NatGateway-CU",
406406
VpcId: VPCID,
407407
CuNum: "3",
408+
BindEips: []string{"100.88.8.210"},
408409
Billing: &Billing{
409410
PaymentTiming: PAYMENT_TIMING_POSTPAID,
410411
},
@@ -1153,6 +1154,24 @@ func TestClient_UnBindDnatEips(t *testing.T) {
11531154
ExpectEqual(t.Errorf, nil, err)
11541155
}
11551156

1157+
func TestClient_EnhanceNatBindEips(t *testing.T) {
1158+
args := &EnhanceNatBindEipsArgs{
1159+
ClientToken: getClientToken(),
1160+
BindEips: []string{"100.88.13.26"},
1161+
}
1162+
err := VPC_CLIENT.EnhanceNatBindEips("nat-bimk2gpe7664", args)
1163+
ExpectEqual(t.Errorf, nil, err)
1164+
}
1165+
1166+
func TestClient_EnhanceNatUnBindEips(t *testing.T) {
1167+
args := &EnhanceNatUnBindEipsArgs{
1168+
ClientToken: getClientToken(),
1169+
BindEips: []string{"100.88.13.26"},
1170+
}
1171+
err := VPC_CLIENT.EnhanceNatUnBindEips("nat-bimk2gpe7664", args)
1172+
ExpectEqual(t.Errorf, nil, err)
1173+
}
1174+
11561175
func TestCreateIpSet(t *testing.T) {
11571176
args := &CreateIpSetArgs{
11581177
ClientToken: getClientToken(),

services/vpc/model.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ type CreateNatGatewayArgs struct {
444444
CuNum string `json:"cuNum,omitempty"`
445445
Eips []string `json:"eips,omitempty"`
446446
DnatEips []string `json:"dnatEips,omitempty"`
447+
BindEips []string `json:"bindEips,omitempty"`
447448
Billing *Billing `json:"billing"`
448449
Tags []model.TagModel `json:"tags,omitempty"`
449450
ResourceGroupId string `json:"resourceGroupId,omitempty"`
@@ -492,12 +493,14 @@ type ListNatGatewayResult struct {
492493
type NAT struct {
493494
Id string `json:"id"`
494495
Name string `json:"name"`
496+
NatType string `json:"natType"`
495497
VpcId string `json:"vpcId"`
496498
Spec string `json:"spec,omitempty"`
497499
CuNum int `json:"cuNum,omitempty"`
498500
Status NatStatusType `json:"status"`
499501
Eips []string `json:"eips"`
500502
DnatEips []string `json:"dnatEips"`
503+
BindEips []string `json:"bindEips"`
501504
PaymentTiming string `json:"paymentTiming"`
502505
ExpiredTime string `json:"expiredTime"`
503506
Tags []model.TagModel `json:"tags"`
@@ -555,6 +558,12 @@ type BindDnatEipsArgs struct {
555558
DnatEips []string `json:"dnatEips"`
556559
}
557560

561+
// EnhanceNatBindEipsArgs defines the structure of the input parameters for the enhanceNatBindEips api
562+
type EnhanceNatBindEipsArgs struct {
563+
ClientToken string `json:"-"`
564+
BindEips []string `json:"bindEips"`
565+
}
566+
558567
// UnBindEipsArgs defines the structure of the input parameters for the UnBindEips api
559568
type UnBindEipsArgs struct {
560569
ClientToken string `json:"-"`
@@ -567,6 +576,12 @@ type UnBindDnatEipsArgs struct {
567576
DnatEips []string `json:"dnatEips"`
568577
}
569578

579+
// EnhanceNatUnBindEipsArgs defines the structure of the input parameters for the EnhanceNatUnBindEips api
580+
type EnhanceNatUnBindEipsArgs struct {
581+
ClientToken string `json:"-"`
582+
BindEips []string `json:"bindEips"`
583+
}
584+
570585
// RenewNatGatewayArgs defines the structure of the input parameters for the RenewNatGateway api
571586
type RenewNatGatewayArgs struct {
572587
ClientToken string `json:"-"`

services/vpc/nat.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,48 @@ func (c *Client) UnBindDnatEips(natId string, args *UnBindDnatEipsArgs) error {
201201
Do()
202202
}
203203

204+
// EnhanceNatBindEips - bind eips for the specific enhanced nat gateway
205+
//
206+
// PARAMS:
207+
// - natId: the id of the specific enhanced nat gateway
208+
// - args: the arguments to bind eips
209+
// RETURNS:
210+
// - error: nil if success otherwise the specific error
211+
func (c *Client) EnhanceNatBindEips(natId string, args *EnhanceNatBindEipsArgs) error {
212+
if args == nil {
213+
return fmt.Errorf("The bindDnatEipsArgs cannot be nil.")
214+
}
215+
216+
return bce.NewRequestBuilder(c).
217+
WithURL(getURLForNatId(natId)).
218+
WithMethod(http.PUT).
219+
WithBody(args).
220+
WithQueryParamFilter("clientToken", args.ClientToken).
221+
WithQueryParam("bind", "").
222+
Do()
223+
}
224+
225+
// EnhanceNatUnBindEips - unbind eips for the specific enhanced nat gateway
226+
//
227+
// PARAMS:
228+
// - natId: the id of the specific enhanced nat gateway
229+
// - args: the arguments to unbind eips
230+
// RETURNS:
231+
// - error: nil if success otherwise the specific error
232+
func (c *Client) EnhanceNatUnBindEips(natId string, args *EnhanceNatUnBindEipsArgs) error {
233+
if args == nil {
234+
return fmt.Errorf("the unBindDnatEipArgs cannot be nil")
235+
}
236+
237+
return bce.NewRequestBuilder(c).
238+
WithURL(getURLForNatId(natId)).
239+
WithMethod(http.PUT).
240+
WithBody(args).
241+
WithQueryParamFilter("clientToken", args.ClientToken).
242+
WithQueryParam("unbind", "").
243+
Do()
244+
}
245+
204246
// DeleteNatGateway - delete the specific nat gateway
205247
//
206248
// PARAMS:

0 commit comments

Comments
 (0)