Skip to content

Commit

Permalink
Add features in bcc, cce and vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Dec 20, 2024
1 parent 6fc9e39 commit 8b74812
Show file tree
Hide file tree
Showing 40 changed files with 1,496 additions and 71 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.208"
SDK_VERSION = "0.9.209"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
44 changes: 44 additions & 0 deletions doc/BCC.md
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,50 @@ if res, err := BCC_CLIENT.GetAllStocks(); err != nil {
}
```
### 查询用户可购买的套餐,按规格族进行分类,按cpu、memory进行排序
- 只返回用户可见的bcc套餐。
- 该接口不支持查询ebc套餐。
```go
if res, err := BCC_CLIENT.GetSortedInstFlavors(); err != nil {
fmt.Println("get sorted inst flavors failed: ", err)
} else {
fmt.Println("get sorted inst flavors success, result: ", res)
}
```
### 通过spec,logicalZone,rootOnLocal 查询可购买bcc套餐抢占库存
- 按照套餐传入的顺序依次计算,先传先抢占资源,一般建议先传同一个规格族下的大规格套餐,再传小规格套餐。
- 一次性传入的套餐列表大小在 [1,100] 之间,超过该范围会报错。
- 该接口的库存(inventoryQuantity)计算说明:假设只有一台100c的物理机,先传入大规格50c套餐,再传入小规格2c套餐,
库存计算有大套餐优先抢占物理机资源原则,那么50c的套餐的库存是2(可买出来2个实例),
2c的套餐的库存为0(因为物理机已经被50c的抢占了)。
- 查询时需要用户开启查询抢占库存白名单。
- 只查询用户可见的套餐库存。
- 该接口不支持查询ebc套餐。
```go
// 是否是本地系统盘
rootOnLocal := false
args := &api.GetInstOccupyStocksOfVmArgs{
Flavors: []api.OccupyStockFlavor{
{
Spec: "bcc.g5.c4m16",
RootOnLocal: &rootOnLocal,
ZoneName: "cn-bj-a",
},
{
Spec: "bcc.g5.c2m8",
RootOnLocal: &rootOnLocal,
ZoneName: "cn-bj-a",
},
},
}
if res, err := BCC_CLIENT.GetInstOccupyStocksOfVm(args); err != nil {
fmt.Println("get inst occupy stocks of vm failed: ", err)
} else {
fmt.Println("get inst occupy stocks of vm success, result: ", res)
}
```
### 部署集粒度实例套餐库存
查询部署集粒度的实例套餐库存
```go
Expand Down
38 changes: 38 additions & 0 deletions examples/cce/cluster/example_upate_cluster_forbiddelete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cluster

import (
"encoding/json"
"fmt"

ccev2 "github.com/baidubce/bce-sdk-go/services/cce/v2"
)

func UpdateClusterForbidDelete() {
// 用户的Access Key ID和Secret Access Key
AK, SK := "", ""

// 用户指定的endpoint
ENDPOINT := ""

// 初始化一个CCEClient
ccev2Client, err := ccev2.NewClient(AK, SK, ENDPOINT)
if err != nil {
panic(err)
}
clusterID := ""
args := &ccev2.UpdateClusterForbidDeleteArgs{
ClusterID: clusterID,
UpdateClusterForbidDeleteRequest: ccev2.UpdateClusterForbidDeleteRequest{
ForbidDelete: true,
},
}

resp, err := ccev2Client.UpdateClusterForbidDelete(args)
if err != nil {
fmt.Println(err.Error())
return
}

s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
}
3 changes: 2 additions & 1 deletion examples/eni/example_create_eni.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func CreateEni() {
TagValue: "tagValue",
},
},
Description: "go sdk test: create eni", // 弹性网卡描述
Description: "go sdk test: create eni", // 弹性网卡描述
NetworkInterfaceTrafficMode: "standard", // 区分创建弹性RDMA网卡(ERI)和普通弹性网卡(ENI)
}

response, err := ENI_CLIENT.CreateEni(createEniArgs) // 创建eni
Expand Down
33 changes: 33 additions & 0 deletions examples/et/example_associate_et_channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package etexamples

import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/et"
"github.com/baidubce/bce-sdk-go/util"
)

func getClientToken() string {
return util.NewUUID()
}

// AssociateEtChannel
func AssociateEtChannel() {
client, err := et.NewClient("Your AK", "Your SK", "bcc.bj.baidubce.com")
if err != nil {
fmt.Printf("Failed to new et client, err: %v.\n", err)
return
}

args := &et.AssociateEtChannelArgs{
ClientToken: getClientToken(), // client token
EtId: "Your EtId", // et id
EtChannelId: "Your EtChannelId", // et channel id
ExtraChannelId: "Your ExtraChannelId", // extra channel id
}

if err := client.AssociateEtChannel(args); err != nil {
fmt.Printf("Failed to associate et channel, err: %v.\n", err)
return
}
fmt.Println("Successfully associate et channel.")
}
33 changes: 33 additions & 0 deletions examples/et/example_disassociate_et_channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package etexamples

import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/et"
"github.com/baidubce/bce-sdk-go/util"
)

func getClientToken() string {
return util.NewUUID()
}

// DisAssociateEtChannel
func DisAssociateEtChannel() {
client, err := et.NewClient("Your AK", "Your SK", "bcc.bj.baidubce.com")
if err != nil {
fmt.Printf("Failed to new et client, err: %v.\n", err)
return
}

args := &et.DisAssociateEtChannelArgs{
ClientToken: getClientToken(), // client token
EtId: "Your EtId", // et id
EtChannelId: "Your EtChannelId", // et channel id
ExtraChannelId: "Your ExtraChannelId", // extra channel id
}

if err := client.DisAssociateEtChannel(args); err != nil {
fmt.Printf("Failed to disassociate et channel, err: %v.\n", err)
return
}
fmt.Println("Successfully disassociate et channel.")
}
11 changes: 9 additions & 2 deletions examples/localDns/example_list_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ldexample

import (
"fmt"

"github.com/baidubce/bce-sdk-go/services/localDns"
"github.com/baidubce/bce-sdk-go/util"
)
Expand All @@ -22,7 +21,15 @@ func ListRecord() {
}

zoneId := "Your private zone id"
result, err := client.ListRecord(zoneId)
sourceType := "" // 默认为空字符串, 可以指定类型
marker := "" // 首次查询传递空字符串,后续查询时需要传递上次接口返回的marker值
maxKeys := 10 // 每次查询的最大数量
args := &localDns.ListRecordRequest{
SourceType: sourceType,
Marker: marker,
MaxKeys: maxKeys,
}
result, err := client.ListRecord(zoneId, args)
if err != nil {
fmt.Println("list record err:", err)
return
Expand Down
26 changes: 26 additions & 0 deletions examples/vpc/vpc/example_add_ip_address_to_ip_set.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 AddIpAddressToIpSet() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
addIpAddress2IpSetArgs := &vpc.AddIpAddress2IpSetArgs{
ClientToken: clientToken,
IpAddressInfo: []vpc.TemplateIpAddressInfo{ // 添加的IP地址信息,其ipVersion需与指定的IP地址组保持一致,单次最多指定10个
{IpAddress: "192.168.11.0/24", Description: "test1"},
{IpAddress: "192.168.12.0/24", Description: "test2"},
},
}
ipSetID := "ips-2etsti1g24hv"
err := client.AddIpAddress2IpSet(ipSetID, addIpAddress2IpSetArgs) // IP地址组添加IP地址

if err != nil {
fmt.Println(err)
}
}
26 changes: 26 additions & 0 deletions examples/vpc/vpc/example_add_ip_set_to_ip_group.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 AddIpSetToIpGroup() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
addIpSetToIpGroupArgs := &vpc.AddIpSet2IpGroupArgs{
ClientToken: clientToken,
IpSetIds: []string{ // 关联的IP地址组ID,其ipVersion需与指定的IP地址族一致,单次最多指定5个
"ips-5eekehr75vbv",
"ips-vn4nfjau2t2u",
},
}
ipGroupID := "ipg-9vd6xtyjz0in"
err := client.AddIpSet2IpGroup(ipGroupID, addIpSetToIpGroupArgs) // IP地址族添加IP地址组

if err != nil {
fmt.Println(err)
}
}
30 changes: 30 additions & 0 deletions examples/vpc/vpc/example_create_ip_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package vpcexamples

import (
"fmt"

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

func CreateIpGroup() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
createIpGroupArgs := &vpc.CreateIpGroupArgs{
ClientToken: clientToken,
Name: "test_create_ip_set", // IP地址族的名称
IpVersion: "IPv4", // ipVersion,取值IPv4或IPv6
IpSetIds: []string{ // 关联的IP地址组ID,其ipVersion需与本次创建的IP地址族一致,单次最多指定5个
"ips-z2a8uk9qnkc1",
"ips-hms1n8fu184f",
},
Description: "this is a test", //IP地址族描述
}

response, err := client.CreateIpGroup(createIpGroupArgs)

if err != nil {
fmt.Println(err)
}
fmt.Println(response)
}
30 changes: 30 additions & 0 deletions examples/vpc/vpc/example_create_ip_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package vpcexamples

import (
"fmt"

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

func CreateIpSet() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
createIpSetArgs := &vpc.CreateIpSetArgs{
ClientToken: clientToken,
Name: "test_create_ip_set", // IP地址组的名称
IpVersion: "IPv4", // ipVersion,取值IPv4或IPv6
IpAddressInfo: []vpc.TemplateIpAddressInfo{ // 参数模板IP地址信息,单次最多指定10个
{IpAddress: "192.168.11.0/24", Description: "test1"},
{IpAddress: "192.168.12.0/24", Description: "test2"},
},
Description: "this is a test", // IP地址组描述
}

response, err := client.CreateIpSet(createIpSetArgs) // 创建IP地址组

if err != nil {
fmt.Println(err)
}
fmt.Println(response)
}
26 changes: 26 additions & 0 deletions examples/vpc/vpc/example_del_ip_address.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 DelIpAddress() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
delIpAddressArgs := &vpc.DelIpAddressArgs{
ClientToken: clientToken,
IpAddressInfo: []string{
"192.168.11.0/24",
"192.168.12.0/24",
},
}
IpSetID := "ips-2etsti1g24hv"
err := client.DelIpAddress(IpSetID, delIpAddressArgs) // 创建vpc

if err != nil {
fmt.Println(err)
}
}
22 changes: 22 additions & 0 deletions examples/vpc/vpc/example_del_ip_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package vpcexamples

import (
"fmt"

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

func DelIpSet() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
delIpSetArgs := &vpc.DelIpSetArgs{
ClientToken: clientToken,
}
IpSetID := "ips-2etsti1g24hv"
err := client.DelIpSet(IpSetID, delIpSetArgs) // 创建vpc

if err != nil {
fmt.Println(err)
}
}
26 changes: 26 additions & 0 deletions examples/vpc/vpc/example_delete_ip_address.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 DeleteIpAddress() {
ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint
client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client
clientToken := "c587aab8-cc6d-4e36-a7a6-b78339b1469f" //幂等性Token,是一个长度不超过64位的ASCII字符串,详见ClientToken幂等性支持。
deleteIpAddressArgs := &vpc.DeleteIpAddressArgs{
ClientToken: clientToken,
IpAddressInfo: []string{ // 删除的IP地址信息,单次最多指定10个
"192.168.11.0/24",
"192.168.12.0/24",
},
}
ipSetID := "ips-2etsti1g24hv"
err := client.DeleteIpAddress(ipSetID, deleteIpAddressArgs) // IP地址组删除IP地址

if err != nil {
fmt.Println(err)
}
}
Loading

0 comments on commit 8b74812

Please sign in to comment.