Skip to content

Commit

Permalink
Add features in bcc and nat
Browse files Browse the repository at this point in the history
  • Loading branch information
liegu committed Feb 14, 2025
1 parent 868bf01 commit 9125be3
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
发行说明:记录每次SDK更新的说明,最新版本的SDK包含以前所有版本的更新内容。
---------------------------------------------------------------------
【版本:v0.9.217】
涉及产品:BCC
创建实例支持CDS加密
涉及产品:NAT
支持增强型NAT
【版本:v0.9.216】
涉及产品:HPAS
修改创建券、查询券、查询镜像列表等接口的参数命名
Expand Down
2 changes: 2 additions & 0 deletions examples/vpc/nat/example_create_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func CreateNat() {
Eips: []string{},
// 设置nat网关的dnat eip列表
DnatEips: []string{},
// 设置nat网关的bind eip列表
BindEips: []string{},
// 设置nat绑定的资源组ID,此字段选传,传则表示绑定资源组
ResourceGroupId: "ResourceGroupId",
// 设置nat网关的计费信息
Expand Down
26 changes: 26 additions & 0 deletions examples/vpc/nat/example_enhance_nat_bind_eip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vpcexamples

import (
"fmt"

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

// 以下为示例代码,实际开发中请根据需要进行修改和补充

func EnhanceNatBindEip() {
ak, sk, endpoint := "Your AK", "Your SK", "bcc.bj.baidubce.com"

natClient, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client

NatID := "Your nat's id"

args := &vpc.EnhanceNatBindEipsArgs{
// 设置要绑定的 EIP 列表
BindEips: []string{"180.76.186.174"}, // 替换为需要绑定的 EIP 列表
}
if err := natClient.EnhanceNatBindEips(NatID, args); err != nil {
fmt.Println("bind eips error: ", err)
return
}
}
26 changes: 26 additions & 0 deletions examples/vpc/nat/example_enhance_nat_unbind_eip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vpcexamples

import (
"fmt"

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

// 以下为示例代码,实际开发中请根据需要进行修改和补充

func EnhanceNatUnBindEip() {
ak, sk, endpoint := "Your AK", "Your SK", "bcc.bj.baidubce.com"

natClient, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client

NatID := "Your nat's id"

args := &vpc.EnhanceNatUnBindEipsArgs{
// 设置要解绑的 EIP 列表
BindEips: []string{"180.76.186.174"}, // 替换为需要解绑的 EIP 列表
}
if err := natClient.EnhanceNatUnBindEips(NatID, args); err != nil {
fmt.Println("unbind eips error: ", err)
return
}
}
4 changes: 4 additions & 0 deletions examples/vpc/nat/example_get_nat_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ func GetNatDetail() {
fmt.Println("nat name: ", result.Name)
// 查询得到nat网关所属的vpc id
fmt.Println("nat vpcId: ", result.VpcId)
// 查询得到nat网关类型,增强型或者普通型
fmt.Println("nat type: ", result.NatType)
// 查询得到nat网关的大小
fmt.Println("nat spec: ", result.Spec)
// 查询得到nat网关绑定的snat EIP的IP地址列表
fmt.Println("nat snat eips: ", result.Eips)
// 查询得到nat网关绑定的dnat EIP的IP地址列表
fmt.Println("nat dnat eips: ", result.DnatEips)
// 查询得到增强型nat网关绑定的bind EIP的IP地址列表
fmt.Println("nat bind eips: ", result.BindEips)
// 查询得到nat网关的状态
fmt.Println("nat status: ", result.Status)
// 查询得到nat网关的付费方式
Expand Down
2 changes: 2 additions & 0 deletions examples/vpc/nat/example_list_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func ListNat() {
fmt.Println("nat id: ", nat.Id)
fmt.Println("nat name: ", nat.Name)
fmt.Println("nat vpcId: ", nat.VpcId)
fmt.Println("nat type: ", nat.NatType)
fmt.Println("nat spec: ", nat.Spec)
fmt.Println("nat snat eips: ", nat.Eips)
fmt.Println("nat dnat eips: ", nat.DnatEips)
fmt.Println("nat bind eips: ", nat.BindEips)
fmt.Println("nat status: ", nat.Status)
fmt.Println("nat paymentTiming: ", nat.PaymentTiming)
fmt.Println("nat expireTime: ", nat.ExpiredTime)
Expand Down
2 changes: 2 additions & 0 deletions services/bcc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ type CreateCdsModel struct {
CdsSizeInGB int `json:"cdsSizeInGB"`
StorageType StorageType `json:"storageType"`
SnapShotId string `json:"snapshotId,omitempty"`
EncryptKey string `json:"encryptKey,omitempty"`
}

type CreateCdsModelV3 struct {
CdsSizeInGB int `json:"cdsSizeInGB"`
StorageType StorageTypeV3 `json:"storageType"`
SnapShotId string `json:"snapshotId,omitempty"`
EncryptKey string `json:"encryptKey,omitempty"`
}

type DiskInfo struct {
Expand Down
19 changes: 19 additions & 0 deletions services/vpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func TestCreateEnhanceNatGateway(t *testing.T) {
Name: "Test-SDK-NatGateway-CU",
VpcId: VPCID,
CuNum: "3",
BindEips: []string{"100.88.8.210"},
Billing: &Billing{
PaymentTiming: PAYMENT_TIMING_POSTPAID,
},
Expand Down Expand Up @@ -1153,6 +1154,24 @@ func TestClient_UnBindDnatEips(t *testing.T) {
ExpectEqual(t.Errorf, nil, err)
}

func TestClient_EnhanceNatBindEips(t *testing.T) {
args := &EnhanceNatBindEipsArgs{
ClientToken: getClientToken(),
BindEips: []string{"100.88.13.26"},
}
err := VPC_CLIENT.EnhanceNatBindEips("nat-bimk2gpe7664", args)
ExpectEqual(t.Errorf, nil, err)
}

func TestClient_EnhanceNatUnBindEips(t *testing.T) {
args := &EnhanceNatUnBindEipsArgs{
ClientToken: getClientToken(),
BindEips: []string{"100.88.13.26"},
}
err := VPC_CLIENT.EnhanceNatUnBindEips("nat-bimk2gpe7664", args)
ExpectEqual(t.Errorf, nil, err)
}

func TestCreateIpSet(t *testing.T) {
args := &CreateIpSetArgs{
ClientToken: getClientToken(),
Expand Down
15 changes: 15 additions & 0 deletions services/vpc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ type CreateNatGatewayArgs struct {
CuNum string `json:"cuNum,omitempty"`
Eips []string `json:"eips,omitempty"`
DnatEips []string `json:"dnatEips,omitempty"`
BindEips []string `json:"bindEips,omitempty"`
Billing *Billing `json:"billing"`
Tags []model.TagModel `json:"tags,omitempty"`
ResourceGroupId string `json:"resourceGroupId,omitempty"`
Expand Down Expand Up @@ -492,12 +493,14 @@ type ListNatGatewayResult struct {
type NAT struct {
Id string `json:"id"`
Name string `json:"name"`
NatType string `json:"natType"`
VpcId string `json:"vpcId"`
Spec string `json:"spec,omitempty"`
CuNum int `json:"cuNum,omitempty"`
Status NatStatusType `json:"status"`
Eips []string `json:"eips"`
DnatEips []string `json:"dnatEips"`
BindEips []string `json:"bindEips"`
PaymentTiming string `json:"paymentTiming"`
ExpiredTime string `json:"expiredTime"`
Tags []model.TagModel `json:"tags"`
Expand Down Expand Up @@ -555,6 +558,12 @@ type BindDnatEipsArgs struct {
DnatEips []string `json:"dnatEips"`
}

// EnhanceNatBindEipsArgs defines the structure of the input parameters for the enhanceNatBindEips api
type EnhanceNatBindEipsArgs struct {
ClientToken string `json:"-"`
BindEips []string `json:"bindEips"`
}

// UnBindEipsArgs defines the structure of the input parameters for the UnBindEips api
type UnBindEipsArgs struct {
ClientToken string `json:"-"`
Expand All @@ -567,6 +576,12 @@ type UnBindDnatEipsArgs struct {
DnatEips []string `json:"dnatEips"`
}

// EnhanceNatUnBindEipsArgs defines the structure of the input parameters for the EnhanceNatUnBindEips api
type EnhanceNatUnBindEipsArgs struct {
ClientToken string `json:"-"`
BindEips []string `json:"bindEips"`
}

// RenewNatGatewayArgs defines the structure of the input parameters for the RenewNatGateway api
type RenewNatGatewayArgs struct {
ClientToken string `json:"-"`
Expand Down
42 changes: 42 additions & 0 deletions services/vpc/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,48 @@ func (c *Client) UnBindDnatEips(natId string, args *UnBindDnatEipsArgs) error {
Do()
}

// EnhanceNatBindEips - bind eips for the specific enhanced nat gateway
//
// PARAMS:
// - natId: the id of the specific enhanced nat gateway
// - args: the arguments to bind eips
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) EnhanceNatBindEips(natId string, args *EnhanceNatBindEipsArgs) error {
if args == nil {
return fmt.Errorf("The bindDnatEipsArgs cannot be nil.")
}

return bce.NewRequestBuilder(c).
WithURL(getURLForNatId(natId)).
WithMethod(http.PUT).
WithBody(args).
WithQueryParamFilter("clientToken", args.ClientToken).
WithQueryParam("bind", "").
Do()
}

// EnhanceNatUnBindEips - unbind eips for the specific enhanced nat gateway
//
// PARAMS:
// - natId: the id of the specific enhanced nat gateway
// - args: the arguments to unbind eips
// RETURNS:
// - error: nil if success otherwise the specific error
func (c *Client) EnhanceNatUnBindEips(natId string, args *EnhanceNatUnBindEipsArgs) error {
if args == nil {
return fmt.Errorf("the unBindDnatEipArgs cannot be nil")
}

return bce.NewRequestBuilder(c).
WithURL(getURLForNatId(natId)).
WithMethod(http.PUT).
WithBody(args).
WithQueryParamFilter("clientToken", args.ClientToken).
WithQueryParam("unbind", "").
Do()
}

// DeleteNatGateway - delete the specific nat gateway
//
// PARAMS:
Expand Down

0 comments on commit 9125be3

Please sign in to comment.