From 8b74812daa68d6f501a9a6d303aee72007afa264 Mon Sep 17 00:00:00 2001 From: duanliguo Date: Fri, 20 Dec 2024 12:07:45 +0800 Subject: [PATCH] Add features in bcc, cce and vpc --- bce/config.go | 2 +- doc/BCC.md | 44 ++++ .../example_upate_cluster_forbiddelete.go | 38 +++ examples/eni/example_create_eni.go | 3 +- examples/et/example_associate_et_channel.go | 33 +++ .../et/example_disassociate_et_channel.go | 33 +++ examples/localDns/example_list_record.go | 11 +- .../vpc/example_add_ip_address_to_ip_set.go | 26 ++ .../vpc/vpc/example_add_ip_set_to_ip_group.go | 26 ++ examples/vpc/vpc/example_create_ip_group.go | 30 +++ examples/vpc/vpc/example_create_ip_set.go | 30 +++ examples/vpc/vpc/example_del_ip_address.go | 26 ++ examples/vpc/vpc/example_del_ip_set.go | 22 ++ examples/vpc/vpc/example_delete_ip_address.go | 26 ++ examples/vpc/vpc/example_delete_ip_group.go | 22 ++ examples/vpc/vpc/example_delete_ip_set.go | 22 ++ .../vpc/vpc/example_get_ip_group_detail.go | 18 ++ examples/vpc/vpc/example_get_ip_set_detail.go | 18 ++ examples/vpc/vpc/example_list_ip_set.go | 23 ++ examples/vpc/vpc/example_unbind_ip_set.go | 26 ++ examples/vpc/vpc/example_update_ip_group.go | 25 ++ examples/vpc/vpc/example_update_ip_set.go | 24 ++ services/bcc/api/instance.go | 94 +++++++ services/bcc/api/model.go | 50 ++++ services/bcc/api/util.go | 31 ++- services/bcc/client.go | 30 +++ services/bcc/client_test.go | 48 +++- services/cce/v2/ccev2.go | 16 ++ services/cce/v2/model.go | 15 ++ services/cce/v2/types/cluster.go | 17 +- services/cce/v2/url.go | 6 + services/eni/client_test.go | 11 +- services/eni/model.go | 21 +- services/et/et.go | 105 +++++--- services/et/model.go | 14 ++ services/vpc/client.go | 28 ++- services/vpc/client_test.go | 161 ++++++++++++ services/vpc/ipSet.go | 22 ++ services/vpc/model.go | 138 +++++++++++ services/vpc/template.go | 232 ++++++++++++++++++ 40 files changed, 1496 insertions(+), 71 deletions(-) create mode 100644 examples/cce/cluster/example_upate_cluster_forbiddelete.go create mode 100644 examples/et/example_associate_et_channel.go create mode 100644 examples/et/example_disassociate_et_channel.go create mode 100644 examples/vpc/vpc/example_add_ip_address_to_ip_set.go create mode 100644 examples/vpc/vpc/example_add_ip_set_to_ip_group.go create mode 100644 examples/vpc/vpc/example_create_ip_group.go create mode 100644 examples/vpc/vpc/example_create_ip_set.go create mode 100644 examples/vpc/vpc/example_del_ip_address.go create mode 100644 examples/vpc/vpc/example_del_ip_set.go create mode 100644 examples/vpc/vpc/example_delete_ip_address.go create mode 100644 examples/vpc/vpc/example_delete_ip_group.go create mode 100644 examples/vpc/vpc/example_delete_ip_set.go create mode 100644 examples/vpc/vpc/example_get_ip_group_detail.go create mode 100644 examples/vpc/vpc/example_get_ip_set_detail.go create mode 100644 examples/vpc/vpc/example_list_ip_set.go create mode 100644 examples/vpc/vpc/example_unbind_ip_set.go create mode 100644 examples/vpc/vpc/example_update_ip_group.go create mode 100644 examples/vpc/vpc/example_update_ip_set.go create mode 100644 services/vpc/ipSet.go create mode 100644 services/vpc/template.go diff --git a/bce/config.go b/bce/config.go index a1c2f3a3..cf05011e 100644 --- a/bce/config.go +++ b/bce/config.go @@ -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" diff --git a/doc/BCC.md b/doc/BCC.md index f087310c..80150dfa 100644 --- a/doc/BCC.md +++ b/doc/BCC.md @@ -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 diff --git a/examples/cce/cluster/example_upate_cluster_forbiddelete.go b/examples/cce/cluster/example_upate_cluster_forbiddelete.go new file mode 100644 index 00000000..5110e6df --- /dev/null +++ b/examples/cce/cluster/example_upate_cluster_forbiddelete.go @@ -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)) +} diff --git a/examples/eni/example_create_eni.go b/examples/eni/example_create_eni.go index e0ba19bf..02227e60 100644 --- a/examples/eni/example_create_eni.go +++ b/examples/eni/example_create_eni.go @@ -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 diff --git a/examples/et/example_associate_et_channel.go b/examples/et/example_associate_et_channel.go new file mode 100644 index 00000000..9da98621 --- /dev/null +++ b/examples/et/example_associate_et_channel.go @@ -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.") +} diff --git a/examples/et/example_disassociate_et_channel.go b/examples/et/example_disassociate_et_channel.go new file mode 100644 index 00000000..950c2dd0 --- /dev/null +++ b/examples/et/example_disassociate_et_channel.go @@ -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.") +} diff --git a/examples/localDns/example_list_record.go b/examples/localDns/example_list_record.go index 3c7fea47..571eb92e 100644 --- a/examples/localDns/example_list_record.go +++ b/examples/localDns/example_list_record.go @@ -2,7 +2,6 @@ package ldexample import ( "fmt" - "github.com/baidubce/bce-sdk-go/services/localDns" "github.com/baidubce/bce-sdk-go/util" ) @@ -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 diff --git a/examples/vpc/vpc/example_add_ip_address_to_ip_set.go b/examples/vpc/vpc/example_add_ip_address_to_ip_set.go new file mode 100644 index 00000000..b3bddedb --- /dev/null +++ b/examples/vpc/vpc/example_add_ip_address_to_ip_set.go @@ -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) + } +} diff --git a/examples/vpc/vpc/example_add_ip_set_to_ip_group.go b/examples/vpc/vpc/example_add_ip_set_to_ip_group.go new file mode 100644 index 00000000..f70af2fc --- /dev/null +++ b/examples/vpc/vpc/example_add_ip_set_to_ip_group.go @@ -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) + } +} diff --git a/examples/vpc/vpc/example_create_ip_group.go b/examples/vpc/vpc/example_create_ip_group.go new file mode 100644 index 00000000..597efd6a --- /dev/null +++ b/examples/vpc/vpc/example_create_ip_group.go @@ -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) +} diff --git a/examples/vpc/vpc/example_create_ip_set.go b/examples/vpc/vpc/example_create_ip_set.go new file mode 100644 index 00000000..29cb6e52 --- /dev/null +++ b/examples/vpc/vpc/example_create_ip_set.go @@ -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) +} diff --git a/examples/vpc/vpc/example_del_ip_address.go b/examples/vpc/vpc/example_del_ip_address.go new file mode 100644 index 00000000..2c383d5c --- /dev/null +++ b/examples/vpc/vpc/example_del_ip_address.go @@ -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) + } +} diff --git a/examples/vpc/vpc/example_del_ip_set.go b/examples/vpc/vpc/example_del_ip_set.go new file mode 100644 index 00000000..1000d259 --- /dev/null +++ b/examples/vpc/vpc/example_del_ip_set.go @@ -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) + } +} diff --git a/examples/vpc/vpc/example_delete_ip_address.go b/examples/vpc/vpc/example_delete_ip_address.go new file mode 100644 index 00000000..2fdf9ceb --- /dev/null +++ b/examples/vpc/vpc/example_delete_ip_address.go @@ -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) + } +} diff --git a/examples/vpc/vpc/example_delete_ip_group.go b/examples/vpc/vpc/example_delete_ip_group.go new file mode 100644 index 00000000..09b862c2 --- /dev/null +++ b/examples/vpc/vpc/example_delete_ip_group.go @@ -0,0 +1,22 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func DeleteIpGroup() { + 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幂等性支持。 + deleteIpGroupArgs := &vpc.DeleteIpGroupArgs{ + ClientToken: clientToken, + } + ipGroupID := "ipg-riivgeymsiwe" // IP地址族的ID + err := client.DeleteIpGroup(ipGroupID, deleteIpGroupArgs) // 删除IP地址族 + + if err != nil { + fmt.Println(err) + } +} diff --git a/examples/vpc/vpc/example_delete_ip_set.go b/examples/vpc/vpc/example_delete_ip_set.go new file mode 100644 index 00000000..c41b5609 --- /dev/null +++ b/examples/vpc/vpc/example_delete_ip_set.go @@ -0,0 +1,22 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func DeleteIpSet() { + 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幂等性支持。 + deleteIpSetArgs := &vpc.DeleteIpSetArgs{ + ClientToken: clientToken, + } + ipSetID := "ips-2etsti1g24hv" // IP地址组的ID + err := client.DeleteIpSet(ipSetID, deleteIpSetArgs) // 删除IP地址组 + + if err != nil { + fmt.Println(err) + } +} diff --git a/examples/vpc/vpc/example_get_ip_group_detail.go b/examples/vpc/vpc/example_get_ip_group_detail.go new file mode 100644 index 00000000..17d8963a --- /dev/null +++ b/examples/vpc/vpc/example_get_ip_group_detail.go @@ -0,0 +1,18 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func GetIpGroupDetail() { + ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint + client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client + ipGroupID := "ipg-kzcc0bfteds6" // IP地址族的ID + response, err := client.GetIpGroupDetail(ipGroupID) // 查询指定的IP地址族 + if err != nil { + fmt.Println(err) + } + fmt.Println(response) +} diff --git a/examples/vpc/vpc/example_get_ip_set_detail.go b/examples/vpc/vpc/example_get_ip_set_detail.go new file mode 100644 index 00000000..1967fbf3 --- /dev/null +++ b/examples/vpc/vpc/example_get_ip_set_detail.go @@ -0,0 +1,18 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func GetIpSetDetail() { + ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint + client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client + ipSetID := "ips-hms1n8fu184f" // IP地址组的ID + response, err := client.GetIpSetDetail(ipSetID) // 查询指定的IP地址组 + if err != nil { + fmt.Println(err) + } + fmt.Println(response) +} diff --git a/examples/vpc/vpc/example_list_ip_set.go b/examples/vpc/vpc/example_list_ip_set.go new file mode 100644 index 00000000..93375fe0 --- /dev/null +++ b/examples/vpc/vpc/example_list_ip_set.go @@ -0,0 +1,23 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func ListIpSet() { + ak, sk, endpoint := "Your Ak", "Your Sk", "Your endpoint" // 初始化ak, sk和endpoint + client, _ := vpc.NewClient(ak, sk, endpoint) // 初始化client + ListIpSetArgs := &vpc.ListIpSetArgs{ + IpVersion: "IPv4", // ipVersion,取值IPv4或IPv6 + Marker: "", // 批量获取列表的查询的起始位置,是一个由系统生成的字符串 + MaxKeys: 2, // 每页包含的最大数量,最大数量不超过1000。缺省值为1000 + } + response, err := client.ListIpSet(ListIpSetArgs) // 查询IP地址组列表 + + if err != nil { + fmt.Println(err) + } + fmt.Println(response) +} diff --git a/examples/vpc/vpc/example_unbind_ip_set.go b/examples/vpc/vpc/example_unbind_ip_set.go new file mode 100644 index 00000000..03d2443c --- /dev/null +++ b/examples/vpc/vpc/example_unbind_ip_set.go @@ -0,0 +1,26 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func UnbindIpSet() { + 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幂等性支持。 + unbindIpsetArgs := &vpc.UnbindIpSetArgs{ + ClientToken: clientToken, + IpSetIds: []string{ // 移除的IP地址组ID,单次最多指定5个 + "ips-5eekehr75vbv", + "ips-vn4nfjau2t2u", + }, + } + ipGroupID := "ipg-9vd6xtyjz0in" // IP地址族的ID + err := client.UnbindIpSet(ipGroupID, unbindIpsetArgs) // IP地址族移除IP地址组 + + if err != nil { + fmt.Println(err) + } +} diff --git a/examples/vpc/vpc/example_update_ip_group.go b/examples/vpc/vpc/example_update_ip_group.go new file mode 100644 index 00000000..0fcdeb97 --- /dev/null +++ b/examples/vpc/vpc/example_update_ip_group.go @@ -0,0 +1,25 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func UpdateIpGroup() { + 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幂等性支持。 + updateIpGroupArgs := &vpc.UpdateIpGroupArgs{ + ClientToken: clientToken, + Name: "test_update_ip_group", // IP地址族的名称 + Description: "this is a test", // IP地址族的描述 + } + + ipGroupID := "ipg-9vd6xtyjz0in" // IP地址族的ID + err := client.UpdateIpGroup(ipGroupID, updateIpGroupArgs) // 更新IP地址族 + + if err != nil { + fmt.Println(err) + } +} diff --git a/examples/vpc/vpc/example_update_ip_set.go b/examples/vpc/vpc/example_update_ip_set.go new file mode 100644 index 00000000..060da77d --- /dev/null +++ b/examples/vpc/vpc/example_update_ip_set.go @@ -0,0 +1,24 @@ +package vpcexamples + +import ( + "fmt" + + "github.com/baidubce/bce-sdk-go/services/vpc" +) + +func UpdateIpSet() { + 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幂等性支持。 + updateIpSetArgs := &vpc.UpdateIpSetArgs{ + Name: "test_update_ip_set", // IP地址组的名称 + Description: "this is a test", // IP地址组的描述 + ClientToken: clientToken, + } + ipSetID := "ips-2etsti1g24hv" // IP地址组的ID + err := client.UpdateIpSet(ipSetID, updateIpSetArgs) // 更新IP地址组 + + if err != nil { + fmt.Println(err) + } +} diff --git a/services/bcc/api/instance.go b/services/bcc/api/instance.go index 63b69474..11bcdeca 100644 --- a/services/bcc/api/instance.go +++ b/services/bcc/api/instance.go @@ -1766,6 +1766,77 @@ func GetAvailableStockWithSpec(cli bce.Client, args *GetAvailableStockWithSpecAr return jsonBody, nil } +// GetSortedInstFlavors - get the sorted instance flavors +// +// PARAMS: +// - cli: the client agent which can perform sending request +// +// RETURNS: +// - *GetSortedInstFlavorsResults: the result of the sorted instance flavors +// - error: nil if success otherwise the specific error +func GetSortedInstFlavors(cli bce.Client) (*GetSortedInstFlavorsResults, error) { + // Build the request + req := &bce.BceRequest{} + req.SetUri(getSortedInstFlavors()) + req.SetMethod(http.POST) + + // 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 := &GetSortedInstFlavorsResults{} + if err := resp.ParseJsonBody(jsonBody); err != nil { + return nil, err + } + return jsonBody, nil +} + +// GetInstOccupyStocksOfVm - get the bcc's occupy stock with spec, logicalZone, rootOnLocal +// +// PARAMS: +// - cli: the client agent which can perform sending request +// - args: the arguments to get the bcc's occupy stock with spec, logicalZone, rootOnLocal +// +// RETURNS: +// - *GetInstOccupyStocksOfVmResults: the result of the bcc's occupy stock +// - error: nil if success otherwise the specific error +func GetInstOccupyStocksOfVm(cli bce.Client, args *GetInstOccupyStocksOfVmArgs) (*GetInstOccupyStocksOfVmResults, error) { + // Build the request + req := &bce.BceRequest{} + req.SetUri(getInstOccupyStocksOfVm()) + req.SetMethod(http.POST) + + 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 := &GetInstOccupyStocksOfVmResults{} + if err := resp.ParseJsonBody(jsonBody); err != nil { + return nil, err + } + return jsonBody, nil +} + // GetStockWithSpec - get the bcc's stock with spec // // PARAMS: @@ -2658,3 +2729,26 @@ func EhcClusterDelete(cli bce.Client, reqBody *bce.Body) error { return nil } + +func GetInstanceUserDataAttr(cli bce.Client, reqBody *bce.Body) (*InstanceUserDataAttrResult, error) { + // Build the request + req := &bce.BceRequest{} + req.SetUri(getInstanceUserDataUri()) + req.SetMethod(http.POST) + req.SetBody(reqBody) + // 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 := &InstanceUserDataAttrResult{} + if err := resp.ParseJsonBody(jsonBody); err != nil { + return nil, err + } + + return jsonBody, nil +} diff --git a/services/bcc/api/model.go b/services/bcc/api/model.go index d17e7e34..db90c410 100644 --- a/services/bcc/api/model.go +++ b/services/bcc/api/model.go @@ -195,6 +195,13 @@ type BccStock struct { ZoneName string `json:"logicalZone"` } +type BccOnlineStock struct { + Spec string `json:"spec"` + InventoryQuantity int `json:"inventoryQuantity"` + RootOnLocal bool `json:"rootOnLocal"` + ZoneName string `json:"logicalZone"` +} + type BbcStock struct { FlavorId string `json:"flavorId"` InventoryQuantity int `json:"inventoryQuantity"` @@ -464,6 +471,24 @@ type GetAvailableStockWithSpecResults struct { BccStocks []BccStock `json:"bccStocks"` } +type GetInstOccupyStocksOfVmArgs struct { + Flavors []OccupyStockFlavor `json:"flavors"` +} + +type OccupyStockFlavor struct { + Spec string `json:"spec"` + RootOnLocal *bool `json:"rootOnLocal,omitempty"` + ZoneName string `json:"logicalZone"` +} + +type GetInstOccupyStocksOfVmResults struct { + BccStocks []BccOnlineStock `json:"bccStocks"` +} + +type GetSortedInstFlavorsResults struct { + ZoneResources []SortedZoneResource `json:"zoneResources"` +} + type GetStockWithSpecResults struct { BccStocks []BccStock `json:"bccStocks"` } @@ -776,6 +801,11 @@ type ListInstanceResult struct { Instances []InstanceModel `json:"instances"` } +type InstanceUserDataAttrResult struct { + UserData string `json:"userData"` + InstanceId string `json:"instanceId"` +} + type ListRecycleInstanceArgs struct { Marker string `json:"marker,omitempty"` MaxKeys int `json:"maxKeys,omitempty"` @@ -1019,6 +1049,22 @@ type Flavor struct { Spec string `json:"spec"` } +type SortedZoneResource struct { + ZoneName string `json:"logicalZone"` + BccResources []SortedBccResource `json:"bccResources"` +} + +type SortedBccResource struct { + SpecId string `json:"specId"` + Flavors []SimpleFlavor `json:"flavors"` +} + +type SimpleFlavor struct { + Spec string `json:"spec"` + CpuCount int `json:"cpuCount"` + MemoryCapacityInGB int `json:"memoryCapacityInGB"` +} + type PurchaseReservedArgs struct { RelatedRenewFlag string `json:"relatedRenewFlag"` Billing Billing `json:"billing"` @@ -2658,6 +2704,10 @@ type DescribeEhcClusterListArg struct { SortDir string `json:"sortDir,omitempty"` } +type DescribeInstanceUserDataArg struct { + InstanceId string `json:"instanceId"` +} + type ModifyReservedInstancesArgs struct { ClientToken string `json:"-"` ReservedInstances []ModifyReservedInstance `json:"reservedInstances"` diff --git a/services/bcc/api/util.go b/services/bcc/api/util.go index a668302b..bf3bd4c3 100644 --- a/services/bcc/api/util.go +++ b/services/bcc/api/util.go @@ -58,12 +58,14 @@ const ( REQUEST_DELETEPREPAY = "/volume/deletePrepay" // - REQUEST_FLAVOR_SPEC_URI = "/instance/flavorSpec" - REQUEST_PRICE_URI = "/price" - REQUEST_AUTO_RENEW_URI = "/autoRenew" - REQUEST_CANCEL_AUTO_RENEW_URI = "/cancelAutoRenew" - REQUEST_BID_PRICE_URI = "/bidPrice" - REQUEST_BID_FLAVOR_URI = "/bidFlavor" + REQUEST_FLAVOR_SPEC_URI = "/instance/flavorSpec" + REQUEST_STOCK_GET_SORTED_INST_FLAVORS_URI = "/stock/getSortedInstFlavors" + REQUEST_STOCK_GET_INST_OCCUPY_STOCKS_OF_VM_URI = "/stock/getInstOccupyStocksOfVM" + REQUEST_PRICE_URI = "/price" + REQUEST_AUTO_RENEW_URI = "/autoRenew" + REQUEST_CANCEL_AUTO_RENEW_URI = "/cancelAutoRenew" + REQUEST_BID_PRICE_URI = "/bidPrice" + REQUEST_BID_FLAVOR_URI = "/bidFlavor" // REQUEST_INSTANCE_PRICE_URI = "/instance/price" @@ -91,7 +93,7 @@ const ( REQUEST_TRANSFER_ACCEPT_URI = "/reserved/transfer/accept" REQUEST_TRANSFER_IN_URI = "/reserved/transfer/in/list" REQUEST_TRANSFER_OUT_URI = "/reserved/transfer/out/list" - REQUEST_RESERVED_LIST_URI = "/reserved/list" + REQUEST_RESERVED_LIST_URI = "/reserved/list" REQUEST_RELATED_DELETE_POLICY = "/modifyRelatedDeletePolicy" REQUEST_VOLUME_PRICE_URI = "/volume/getPrice" @@ -100,6 +102,7 @@ const ( REQUEST_EHC_CLUSTER_LIST_URI = "/ehc/cluster/list" REQUEST_EHC_CLUSTER_MODIFY_URI = "/ehc/cluster/modify" REQUEST_EHC_CLUSTER_DELETE_URI = "/ehc/cluster/delete" + REQUEST_INSTANCE_USER_DATA_URI = "/attribute/getUserdata" ) func getInstanceUri() string { @@ -315,6 +318,14 @@ func getAvailableStockWithSpec() string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_GET_AVAILABLE_STOCK_WITH_SPEC } +func getSortedInstFlavors() string { + return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_STOCK_GET_SORTED_INST_FLAVORS_URI +} + +func getInstOccupyStocksOfVm() string { + return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_STOCK_GET_INST_OCCUPY_STOCKS_OF_VM_URI +} + func getCreateInstanceStock() string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + "/stock/createInstance" } @@ -504,7 +515,7 @@ func getAvailableImagesBySpecUri() string { } func getListReservedInstancesUri() string { - return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_RESERVED_LIST_URI; + return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_RESERVED_LIST_URI } func getCreateTransferReservedInstanceOrderUri() string { @@ -550,3 +561,7 @@ func getEhcClusterModifyUri() string { func getEhcClusterDeleteUri() string { return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_EHC_CLUSTER_DELETE_URI } + +func getInstanceUserDataUri() string { + return URI_PREFIXV2 + REQUEST_INSTANCE_URI + REQUEST_INSTANCE_USER_DATA_URI +} diff --git a/services/bcc/client.go b/services/bcc/client.go index 462056de..9f188a16 100644 --- a/services/bcc/client.go +++ b/services/bcc/client.go @@ -2019,6 +2019,24 @@ func (c *Client) GetAvailableStockWithSpec(args *api.GetAvailableStockWithSpecAr return api.GetAvailableStockWithSpec(c, args) } +// GetSortedInstFlavors - get the sorted instance flavors +// +// RETURNS: +// - *GetSortedInstFlavorsResults: the result of the sorted instance flavors +// - error: nil if success otherwise the specific error +func (c *Client) GetSortedInstFlavors() (*api.GetSortedInstFlavorsResults, error) { + return api.GetSortedInstFlavors(c) +} + +// GetInstOccupyStocksOfVm - get the bcc's occupy stock with spec, logicalZone, rootOnLocal +// +// RETURNS: +// - *GetInstOccupyStocksOfVmResults: the result of the bcc's occupy stock +// - error: nil if success otherwise the specific error +func (c *Client) GetInstOccupyStocksOfVm(args *api.GetInstOccupyStocksOfVmArgs) (*api.GetInstOccupyStocksOfVmResults, error) { + return api.GetInstOccupyStocksOfVm(c, args) +} + func (c *Client) GetInstanceCreateStock(args *api.CreateInstanceStockArgs) (*api.InstanceStockResult, error) { return api.GetInstanceCreateStock(c, args) } @@ -2600,6 +2618,18 @@ func (c *Client) ListEhcCluster(args *api.DescribeEhcClusterListArg) (*api.Descr return api.EhcClusterList(c, body) } +func (c *Client) getInstanceUserData(args *api.DescribeInstanceUserDataArg) (*api.InstanceUserDataAttrResult, error) { + jsonBytes, jsonErr := json.Marshal(args) + if jsonErr != nil { + return nil, jsonErr + } + body, err := bce.NewBodyFromBytes(jsonBytes) + if err != nil { + return nil, err + } + return api.GetInstanceUserDataAttr(c, body) +} + // ModifyEhcCluster - modify ehcCluster // // PARAMS: diff --git a/services/bcc/client_test.go b/services/bcc/client_test.go index aeeab8c4..2f640c6f 100644 --- a/services/bcc/client_test.go +++ b/services/bcc/client_test.go @@ -970,7 +970,7 @@ func TestListZone(t *testing.T) { func TestListFlavorSpec(t *testing.T) { args := &api.ListFlavorSpecArgs{ - Specs: "bcc.g5.c2m8", + Specs: "bcc.g5.c2m8", ZoneName: "cn-bj-b", } res, err := BCC_CLIENT.ListFlavorSpec(args) @@ -1924,6 +1924,35 @@ func TestGetAvailableStockWithSpec(t *testing.T) { fmt.Println(result) } +func TestGetSortedInstFlavors(t *testing.T) { + 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) + } +} + +func TestGetInstOccupyStocksOfVm(t *testing.T) { + 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", + }, + }, + } + result, err := BCC_CLIENT.GetInstOccupyStocksOfVm(args) + ExpectEqual(t.Errorf, err, nil) + fmt.Println(result) +} + func TestModifyRelatedDeletePolicy(t *testing.T) { args := &api.RelatedDeletePolicy{ IsEipAutoRelatedDelete: true, @@ -2082,6 +2111,15 @@ func TestEhcClusterList(t *testing.T) { fmt.Println(err) } +func TestGetInstanceUserData(t *testing.T) { + args := &api.DescribeInstanceUserDataArg{ + InstanceId: "i-b34ycow2", + } + result, err := BCC_CLIENT.getInstanceUserData(args) + fmt.Println(result) + fmt.Println(err) +} + func TestCreateReservedInstance(t *testing.T) { args := &api.CreateReservedInstanceArgs{ ClientToken: "myClientToken1", @@ -2115,7 +2153,6 @@ func TestCreateReservedInstance(t *testing.T) { } func TestCreateReservedInstanceWithoutOptionalParam(t *testing.T) { - args := &api.CreateReservedInstanceArgs{ ClientToken: "myClientToken", ZoneName: "cn-bj-a", @@ -2255,11 +2292,10 @@ func TestClient_GetSecurityDetail(t *testing.T) { func TestModifySnapshotAttribute(t *testing.T) { args := &api.ModifySnapshotAttributeArgs{ - SnapshotName: "test-snapshot", - Desc: "test-desc", - RetentionInDays: 1, + SnapshotName: "test-snapshot", + Desc: "test-desc", + RetentionInDays: 1, } err := BCC_CLIENT.ModifySnapshotAttribute("s-Dzmlx7Fz", args) ExpectEqual(t.Errorf, err, nil) } - diff --git a/services/cce/v2/ccev2.go b/services/cce/v2/ccev2.go index a01e79b7..6e46936d 100644 --- a/services/cce/v2/ccev2.go +++ b/services/cce/v2/ccev2.go @@ -98,6 +98,22 @@ func (c *Client) DeleteCluster(args *DeleteClusterArgs) (*DeleteClusterResponse, return result, err } +func (c *Client) UpdateClusterForbidDelete(args *UpdateClusterForbidDeleteArgs) (*UpdateClusterForbidDeleteResponse, error) { + if args == nil { + return nil, fmt.Errorf("args is nil") + } + + result := &UpdateClusterForbidDeleteResponse{} + err := bce.NewRequestBuilder(c). + WithMethod(http.PUT). + WithURL(getUpdateClusterForbidDeleteURI(args.ClusterID)). + WithBody(args.UpdateClusterForbidDeleteRequest). + WithResult(result). + Do() + + return result, err +} + // 获得集群详情 func (c *Client) GetCluster(clusterID string) (*GetClusterResponse, error) { if clusterID == "" { diff --git a/services/cce/v2/model.go b/services/cce/v2/model.go index 0ea8dede..e6828092 100644 --- a/services/cce/v2/model.go +++ b/services/cce/v2/model.go @@ -70,6 +70,15 @@ type ListClustersArgs struct { PageSize int } +type UpdateClusterForbidDeleteArgs struct { + ClusterID string + UpdateClusterForbidDeleteRequest UpdateClusterForbidDeleteRequest +} + +type UpdateClusterForbidDeleteRequest struct { + ForbidDelete bool +} + type CreateInstancesArgs struct { ClusterID string Instances []*InstanceSet @@ -1016,3 +1025,9 @@ type UpdateAddonArgs struct { AddOnInstanceName string `json:"instanceName,omitempty"` Params string `json:"params,omitempty"` } + +// UpdateClusterForbidDeleteResponse - 更新 ClusterForbidDelete 返回 +type UpdateClusterForbidDeleteResponse struct { + Success bool `json:"success"` + ForbidDelete bool `json:"forbidDelete"` +} diff --git a/services/cce/v2/types/cluster.go b/services/cce/v2/types/cluster.go index e65b8bd3..0384220b 100644 --- a/services/cce/v2/types/cluster.go +++ b/services/cce/v2/types/cluster.go @@ -178,9 +178,24 @@ type MasterConfig struct { // ManagedClusterMasterOption 托管集群 Master 配置 type ManagedClusterMasterOption struct { - MasterVPCSubnetZone AvailableZone `json:"masterVPCSubnetZone,omitempty"` + MasterVPCSubnetZone AvailableZone `json:"masterVPCSubnetZone,omitempty"` + MasterVPCSubnetUUID string `json:"masterVPCSubnetUUID,omitempty"` + MasterSecurityGroupUUID string `json:"masterSecurityGroupUUID,omitempty"` + + MasterFlavor MasterFlavor `json:"masterFlavor,omitempty"` } +type MasterFlavor string + +const ( + MasterFlavorL50 MasterFlavor = "l50" + MasterFlavorL200 MasterFlavor = "l200" + MasterFlavorL500 MasterFlavor = "l500" + MasterFlavorL1000 MasterFlavor = "l1000" + MasterFlavorL3000 MasterFlavor = "l3000" + MasterFlavorL5000 MasterFlavor = "l5000" +) + // RuntimeType defines the runtime on each node type RuntimeType string diff --git a/services/cce/v2/url.go b/services/cce/v2/url.go index 49a1115f..c88093cf 100644 --- a/services/cce/v2/url.go +++ b/services/cce/v2/url.go @@ -73,6 +73,8 @@ const ( REQUEST_SYNC_URL = "/sync" REQUEST_RBAC_URL = "/rbac" + + REQUEST_FORBIDDELETE_URL = "/forbiddelete" ) var _ Interface = &Client{} @@ -117,6 +119,10 @@ func getClusterListURI() string { return URI_PREFIX + REQUEST_CLUSTER_LIST_URL } +func getUpdateClusterForbidDeleteURI(clusterID string) string { + return URI_PREFIX + REQUEST_CLUSTER_URL + "/" + clusterID + REQUEST_FORBIDDELETE_URL +} + func getClusterInstanceListURI(clusterID string) string { return URI_PREFIX + REQUEST_CLUSTER_URL + "/" + clusterID + REQUEST_INSTANCE_LIST_URL } diff --git a/services/eni/client_test.go b/services/eni/client_test.go index df8d0866..e95c0d8f 100644 --- a/services/eni/client_test.go +++ b/services/eni/client_test.go @@ -99,14 +99,14 @@ func getClientToken() string { func TestClient_CreateEni(t *testing.T) { args := &CreateEniArgs{ Name: "GO_SDK_TEST_CREATE_EIP_M", - SubnetId: "sbn-u1ft0w2m1and", + SubnetId: "sbn-x1evbqf9vgxq", EnterpriseSecurityGroupIds: []string{ - "esg-d8e5pi46f2dt", + "esg-p9y1mmu5fqkx", }, PrivateIpSet: []PrivateIp{ { Primary: true, - PrivateIpAddress: "10.0.0.5", + PrivateIpAddress: "192.168.0.23", }, }, Ipv6PrivateIpSet: []PrivateIp{ @@ -121,8 +121,9 @@ func TestClient_CreateEni(t *testing.T) { TagValue: "tagValue", }, }, - Description: "go sdk test", - ClientToken: getClientToken(), + Description: "go sdk test", + ClientToken: getClientToken(), + NetworkInterfaceTrafficMode: "standard", } result, err := ENI_CLIENT.CreateEni(args) ExpectEqual(t.Errorf, nil, err) diff --git a/services/eni/model.go b/services/eni/model.go index 1b75f0f7..a0a23799 100644 --- a/services/eni/model.go +++ b/services/eni/model.go @@ -17,16 +17,17 @@ package eni import "github.com/baidubce/bce-sdk-go/model" type CreateEniArgs struct { - ClientToken string `json:"-"` - Name string `json:"name"` - SubnetId string `json:"subnetId"` - InstanceId string `json:"instanceId,omitempty"` - SecurityGroupIds []string `json:"securityGroupIds"` - EnterpriseSecurityGroupIds []string `json:"enterpriseSecurityGroupIds"` - PrivateIpSet []PrivateIp `json:"privateIpSet"` - Ipv6PrivateIpSet []PrivateIp `json:"ipv6PrivateIpSet,omitempty"` - Description string `json:"description,omitempty"` - Tags []model.TagModel `json:"tags,omitempty"` + ClientToken string `json:"-"` + Name string `json:"name"` + SubnetId string `json:"subnetId"` + InstanceId string `json:"instanceId,omitempty"` + SecurityGroupIds []string `json:"securityGroupIds"` + EnterpriseSecurityGroupIds []string `json:"enterpriseSecurityGroupIds"` + PrivateIpSet []PrivateIp `json:"privateIpSet"` + Ipv6PrivateIpSet []PrivateIp `json:"ipv6PrivateIpSet,omitempty"` + Description string `json:"description,omitempty"` + Tags []model.TagModel `json:"tags,omitempty"` + NetworkInterfaceTrafficMode string `json:"networkInterfaceTrafficMode,omitempty"` } type CreateEniResult struct { diff --git a/services/et/et.go b/services/et/et.go index 6ebf8d2e..7a543e88 100644 --- a/services/et/et.go +++ b/services/et/et.go @@ -27,10 +27,11 @@ import ( // GetEtChannel - get an et channel // // PARAMS: -// - args: the arguments to get et channel +// - args: the arguments to get et channel +// // RETURNS: -// - *GetEtChannelResult: the info of the et channel -// - error: nil if success otherwise the specific error +// - *GetEtChannelResult: the info of the et channel +// - error: nil if success otherwise the specific error func (c *Client) GetEtChannel(args *GetEtChannelArgs) (*GetEtChannelsResult, error) { if args == nil { return nil, fmt.Errorf("The GetEtChannelArgs cannot be nil.") @@ -50,9 +51,10 @@ func (c *Client) GetEtChannel(args *GetEtChannelArgs) (*GetEtChannelsResult, err // RecommitEtChannel - recommit et channel // // PARAMS: -// - args: the arguments to recommit et channel +// - args: the arguments to recommit et channel +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) RecommitEtChannel(args *RecommitEtChannelArgs) error { if args == nil { return fmt.Errorf("The RecommitEtChannelArgs cannot be nil.") @@ -70,9 +72,10 @@ func (c *Client) RecommitEtChannel(args *RecommitEtChannelArgs) error { // UpdateEtChannel - update et channel // // PARAMS: -// - args: the arguments to update et channel +// - args: the arguments to update et channel +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) UpdateEtChannel(args *UpdateEtChannelArgs) error { if args == nil { return fmt.Errorf("The UpdateEtChannelArgs cannot be nil.") @@ -90,9 +93,10 @@ func (c *Client) UpdateEtChannel(args *UpdateEtChannelArgs) error { // DeleteEtChannel - delete et channel // // PARAMS: -// - args: the arguments to delete et channel +// - args: the arguments to delete et channel +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) DeleteEtChannel(args *DeleteEtChannelArgs) error { if args == nil { return fmt.Errorf("The DeleteEtChannelArgs cannot be nil.") @@ -109,9 +113,10 @@ func (c *Client) DeleteEtChannel(args *DeleteEtChannelArgs) error { // EnableEtChannelIPv6 - enable et channel ipv6 // // PARAMS: -// - args: the arguments to enable et channel ipv6 +// - args: the arguments to enable et channel ipv6 +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) EnableEtChannelIPv6(args *EnableEtChannelIPv6Args) error { if args == nil { return fmt.Errorf("The EnableEtChannelIPv6Args cannot be nil.") @@ -146,14 +151,14 @@ func (c *Client) DisableEtChannelIPv6(args *DisableEtChannelIPv6Args) error { Do() } - // CreateEtDcphy - init a new Et // // PARAMS: -// - args: the arguments to init et dcphy +// - args: the arguments to init et dcphy +// // RETURNS: -// - CreateEtDcphyResult: the id of et dcphy newly created -// - error: nil if success otherwise the specific error +// - CreateEtDcphyResult: the id of et dcphy newly created +// - error: nil if success otherwise the specific error func (c *Client) CreateEtDcphy(args *CreateEtDcphyArgs) (*CreateEtDcphyResult, error) { if args == nil { return nil, fmt.Errorf("The CreateEtDcphyArgs can not be nil") @@ -161,7 +166,7 @@ func (c *Client) CreateEtDcphy(args *CreateEtDcphyArgs) (*CreateEtDcphyResult, e result := &CreateEtDcphyResult{} err := bce.NewRequestBuilder(c). - WithURL(getURLForEt() + "/init"). + WithURL(getURLForEt()+"/init"). WithMethod(http.POST). WithBody(args). WithQueryParamFilter("clientToken", args.ClientToken). @@ -174,10 +179,11 @@ func (c *Client) CreateEtDcphy(args *CreateEtDcphyArgs) (*CreateEtDcphyResult, e // UpdateEtDcphy - update an existed Et // // PARAMS: -// - edId: the id of et dcphy -// - args: the arguments to update et dcphy +// - edId: the id of et dcphy +// - args: the arguments to update et dcphy +// // RETURNS: -// - error: nil if success otherwise the specific error +// - error: nil if success otherwise the specific error func (c *Client) UpdateEtDcphy(dcphyId string, args *UpdateEtDcphyArgs) error { if len(dcphyId) == 0 { return fmt.Errorf("please set et dcphy id") @@ -196,10 +202,11 @@ func (c *Client) UpdateEtDcphy(dcphyId string, args *UpdateEtDcphyArgs) error { // ListEtDcphy - List ets // // PARAMS: -// - args: the arguments to list et +// - args: the arguments to list et +// // RETURNS: -// - ListEtDcphyResult: list result -// - error: nil if success otherwise the specific error +// - ListEtDcphyResult: list result +// - error: nil if success otherwise the specific error func (c *Client) ListEtDcphy(args *ListEtDcphyArgs) (*ListEtDcphyResult, error) { if args == nil { args = &ListEtDcphyArgs{} @@ -225,10 +232,11 @@ func (c *Client) ListEtDcphy(args *ListEtDcphyArgs) (*ListEtDcphyResult, error) // ListEtDcphyDetail - List specific et detail // // PARAMS: -// - dcphyId: the id of etDcphy +// - dcphyId: the id of etDcphy +// // RETURNS: -// - EtDcphyDetail: etDcphy detail -// - error: nil if success otherwise the specific error +// - EtDcphyDetail: etDcphy detail +// - error: nil if success otherwise the specific error func (c *Client) ListEtDcphyDetail(dcphyId string) (*EtDcphyDetail, error) { if len(dcphyId) == 0 { return nil, fmt.Errorf("please set et dcphy id") @@ -247,10 +255,11 @@ func (c *Client) ListEtDcphyDetail(dcphyId string) (*EtDcphyDetail, error) { // CreateEtChannel - create an Et channel with the specific parameters // // PARAMS: -// - args: the arguments to create an eip +// - args: the arguments to create an eip +// // RETURNS: -// - CreateEipResult: the result of create EIP, contains new EIP's address -// - error: nil if success otherwise the specific error +// - CreateEipResult: the result of create EIP, contains new EIP's address +// - error: nil if success otherwise the specific error func (c *Client) CreateEtChannel(args *CreateEtChannelArgs) (*CreateEtChannelResult, error) { if args == nil { return nil, fmt.Errorf("please set create etChannel argments") @@ -361,3 +370,43 @@ func (c *Client) DeleteEtChannelRouteRule(args *DeleteEtChannelRouteRuleArgs) er Do() } + +// AssociateEtChannel - associate a specified EtChannel with the specified etChannelId +// +// PARAMS: +// - args: the arguments to associate EtChannel +// +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) AssociateEtChannel(args *AssociateEtChannelArgs) error { + if args == nil { + return fmt.Errorf("the associateEtChannelArgs cannot be nil") + } + return bce.NewRequestBuilder(c). + WithURL(getURLForEtChannelId(args.EtId, args.EtChannelId)). + WithMethod(http.PUT). + WithBody(args). + WithQueryParam("associate", ""). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() +} + +// DisAssociateEtChannel - disassociate a specified EtChannel with the specified etChannelId +// +// PARAMS: +// - args: the arguments to disassociate EtChannel +// +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) DisAssociateEtChannel(args *DisAssociateEtChannelArgs) error { + if args == nil { + return fmt.Errorf("the associateEtChannelArgs cannot be nil") + } + return bce.NewRequestBuilder(c). + WithURL(getURLForEtChannelId(args.EtId, args.EtChannelId)). + WithMethod(http.PUT). + WithBody(args). + WithQueryParam("disassociate", ""). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() +} diff --git a/services/et/model.go b/services/et/model.go index 2b638c13..29e542df 100644 --- a/services/et/model.go +++ b/services/et/model.go @@ -270,3 +270,17 @@ type DeleteEtChannelRouteRuleArgs struct { EtChannelId string `json:"etChannelId"` RouteRuleId string `json:"routeRuleId"` } + +type AssociateEtChannelArgs struct { + ClientToken string `json:"clientToken,omitempty"` + EtId string `json:"etId"` + EtChannelId string `json:"etChannelId"` + ExtraChannelId string `json:"extraChannelId"` +} + +type DisAssociateEtChannelArgs struct { + ClientToken string `json:"clientToken,omitempty"` + EtId string `json:"etId"` + EtChannelId string `json:"etChannelId"` + ExtraChannelId string `json:"extraChannelId"` +} diff --git a/services/vpc/client.go b/services/vpc/client.go index b5761524..ec7c5e85 100644 --- a/services/vpc/client.go +++ b/services/vpc/client.go @@ -27,16 +27,18 @@ const ( DEFAULT_ENDPOINT = "bcc." + bce.DEFAULT_REGION + ".baidubce.com" - REQUEST_VPC_URL = "/vpc" - REQUEST_SUBNET_URL = "/subnet" - REQUEST_ROUTE_URL = "/route" - REQUEST_RULE_URL = "/rule" - REQUEST_ACL_URL = "/acl" - REQUEST_NAT_URL = "/nat" - REQUEST_PEERCONN_URL = "/peerconn" - REQUEST_NETWORK_TOPOLOGY_URL = "/topology" - REQUEST_PROBE_URL = "/probe" + REQUEST_VPC_URL = "/vpc" + REQUEST_SUBNET_URL = "/subnet" + REQUEST_ROUTE_URL = "/route" + REQUEST_RULE_URL = "/rule" + REQUEST_ACL_URL = "/acl" + REQUEST_NAT_URL = "/nat" + REQUEST_PEERCONN_URL = "/peerconn" + REQUEST_NETWORK_TOPOLOGY_URL = "/topology" + REQUEST_PROBE_URL = "/probe" REQUEST_NETWORK_IPV6GATEWAY_URL = "/IPv6Gateway" + REQUEST_IPSET_URL = "/ipSet" + REQUEST_IPGROUP_URL = "/ipGroup" ) // Client of VPC service is a kind of BceClient, so derived from BceClient @@ -143,3 +145,11 @@ func getURLForIpv6Gateway() string { func getURLForIpv6GatewayId(ipv6GatewayId string) string { return getURLForIpv6Gateway() + "/" + ipv6GatewayId } + +func getURLForIpSet() string { return URI_PREFIX + REQUEST_IPSET_URL } + +func getURLForIpSetId(ipSetId string) string { return getURLForIpSet() + "/" + ipSetId } + +func getURLForIpGroup() string { return URI_PREFIX + REQUEST_IPGROUP_URL } + +func getURLForIpGroupId(ipGroupId string) string { return getURLForIpGroup() + "/" + ipGroupId } diff --git a/services/vpc/client_test.go b/services/vpc/client_test.go index 98270996..9616ba05 100644 --- a/services/vpc/client_test.go +++ b/services/vpc/client_test.go @@ -33,6 +33,8 @@ var ( LocalIfID string PeerVPCID string EIPAddress string + IpSetID string + IpGroupID string ) // For security reason, ak/sk should not hard write here. @@ -1150,3 +1152,162 @@ func TestClient_UnBindDnatEips(t *testing.T) { err := VPC_CLIENT.UnBindDnatEips("nat-bc39ugw5ry9z", args) ExpectEqual(t.Errorf, nil, err) } + +func TestCreateIpSet(t *testing.T) { + args := &CreateIpSetArgs{ + ClientToken: getClientToken(), + Name: "test_create_ip_set", + IpVersion: "IPv4", + IpAddressInfo: []TemplateIpAddressInfo{ + {IpAddress: "192.168.11.0/24", Description: "test1"}, + {IpAddress: "192.168.12.0/24", Description: "test2"}, + }, + Description: "this is a test", + } + result, err := VPC_CLIENT.CreateIpSet(args) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} + +func TestAddIpAddress2IpSet(t *testing.T) { + args := &AddIpAddress2IpSetArgs{ + ClientToken: getClientToken(), + IpAddressInfo: []TemplateIpAddressInfo{ + {IpAddress: "192.168.15.1", Description: "test1"}, + {IpAddress: "192.168.16.2", Description: "test2"}, + }, + } + IpSetID = "ips-5eekehr75vbv" + err := VPC_CLIENT.AddIpAddress2IpSet(IpSetID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestDeleteIpAddress(t *testing.T) { + args := &DeleteIpAddressArgs{ + ClientToken: getClientToken(), + IpAddressInfo: []string{ + "192.168.11.0/24", + }, + } + IpSetID = "ips-edk700us464u" + err := VPC_CLIENT.DeleteIpAddress(IpSetID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestUpdateIpSet(t *testing.T) { + args := &UpdateIpSetArgs{ + ClientToken: getClientToken(), + Name: "test_update_ip_set", + Description: "this is a test", + } + IpSetID = "ips-2etsti1g24hv" + err := VPC_CLIENT.UpdateIpSet(IpSetID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestDeleteIpSet(t *testing.T) { + args := &DeleteIpSetArgs{ + ClientToken: getClientToken(), + } + IpSetID = "ips-g1n60tupgsx5" + err := VPC_CLIENT.DeleteIpSet(IpSetID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestListIpSet(t *testing.T) { + args := &ListIpSetArgs{ + IpVersion: "IPv4", + Marker: "", + MaxKeys: 2, + } + result, err := VPC_CLIENT.ListIpSet(args) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} + +func TestGetIpSetDetail(t *testing.T) { + IpSetID = "ips-hms1n8fu184f" + result, err := VPC_CLIENT.GetIpSetDetail(IpSetID) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} + +func TestCreateIpGroup(t *testing.T) { + args := &CreateIpGroupArgs{ + ClientToken: getClientToken(), + Name: "test_create_ip_set", + IpVersion: "IPv4", + IpSetIds: []string{ + "ips-z2a8uk9qnkc1", + "ips-hms1n8fu184f", + }, + Description: "this is a test", + } + result, err := VPC_CLIENT.CreateIpGroup(args) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} + +func TestAddIpSet2IpGroup(t *testing.T) { + args := &AddIpSet2IpGroupArgs{ + ClientToken: getClientToken(), + IpSetIds: []string{"ips-vn4nfjau2t2u"}, + } + IpGroupID = "ipg-95eapsuw195m" + err := VPC_CLIENT.AddIpSet2IpGroup(IpGroupID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestUnbindIpSet(t *testing.T) { + args := &UnbindIpSetArgs{ + ClientToken: getClientToken(), + IpSetIds: []string{"ips-z2a8uk9qnkc1"}, + } + IpGroupID = "ipg-9vd6xtyjz0in" + err := VPC_CLIENT.UnbindIpSet(IpGroupID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestUpdateIpGroup(t *testing.T) { + args := &UpdateIpGroupArgs{ + ClientToken: getClientToken(), + Name: "test_update_ip_group", + Description: "this is a test", + } + IpGroupID = "ipg-9vd6xtyjz0in" + err := VPC_CLIENT.UpdateIpGroup(IpGroupID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestDeleteIpGroup(t *testing.T) { + args := &DeleteIpGroupArgs{ + ClientToken: getClientToken(), + } + IpGroupID = "ipg-riivgeymsiwe" + err := VPC_CLIENT.DeleteIpGroup(IpGroupID, args) + ExpectEqual(t.Errorf, nil, err) +} + +func TestListIpGroup(t *testing.T) { + args := &ListIpGroupArgs{ + IpVersion: "IPv4", + Marker: "", + MaxKeys: 2, + } + result, err := VPC_CLIENT.ListIpGroup(args) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} + +func TestGetIpGroupDetail(t *testing.T) { + IpGroupID = "ipg-kzcc0bfteds6" + result, err := VPC_CLIENT.GetIpGroupDetail(IpGroupID) + ExpectEqual(t.Errorf, nil, err) + r, _ := json.Marshal(result) + fmt.Println(string(r)) +} diff --git a/services/vpc/ipSet.go b/services/vpc/ipSet.go new file mode 100644 index 00000000..e37d749c --- /dev/null +++ b/services/vpc/ipSet.go @@ -0,0 +1,22 @@ +package vpc + +import ( + "fmt" + "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/http" +) + +func (c *Client) CreateIpSet(args *CreateIpSetArgs) (*CreateIpSetResult, error) { + if args == nil { + return nil, fmt.Errorf("The CreateIpSetArgs cannot be nil.") + } + result := &CreateIpSetResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSet()). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + WithResult(result). + Do() + return result, err +} diff --git a/services/vpc/model.go b/services/vpc/model.go index 185581ba..0aa1817b 100644 --- a/services/vpc/model.go +++ b/services/vpc/model.go @@ -1007,3 +1007,141 @@ type UpdateVpcRelayArgs struct { ClientToken string `json:"-"` VpcId string `json:"vpcId"` } + +type TemplateIpAddressInfo struct { + IpAddress string `json:"ipAddress"` + Description string `json:"description"` +} + +type IpSet struct { + IpSetId string `json:"ipSetId"` + Name string `json:"name"` + Description string `json:"description"` + IpVersion string `json:"ipVersion"` + IpAddressInfo []TemplateIpAddressInfo `json:"ipAddressInfo"` + BindedInstanceNum int `json:"bindedInstanceNum"` +} + +type IpCollectionBindedInstance struct { + InstanceId string `json:"instanceId"` + InstanceType string `json:"instanceType"` +} + +type IpGroup struct { + IpGroupId string `json:"ipGroupId"` + Name string `json:"name"` + Description string `json:"description"` + IpVersion string `json:"ipVersion"` + IpSetIds []string `json:"ipSetIds"` + BindedInstanceNum int `json:"bindedInstanceNum"` +} + +type CreateIpSetArgs struct { + ClientToken string `json:"-"` + Name string `json:"name"` + IpVersion string `json:"ipVersion"` + IpAddressInfo []TemplateIpAddressInfo `json:"ipAddressInfo"` + Description string `json:"description"` +} + +type CreateIpSetResult struct { + IpSetId string `json:"ipSetId"` +} + +type AddIpAddress2IpSetArgs struct { + ClientToken string `json:"-"` + IpAddressInfo []TemplateIpAddressInfo `json:"ipAddressInfo"` +} + +type DeleteIpAddressArgs struct { + ClientToken string `json:"-"` + IpAddressInfo []string `json:"ipAddressInfo"` +} + +type UpdateIpSetArgs struct { + ClientToken string `json:"-"` + Name string `json:"name"` + Description string `json:"description"` +} + +type DeleteIpSetArgs struct { + ClientToken string `json:"-"` +} + +type ListIpSetArgs struct { + IpVersion string + Marker string + MaxKeys int +} + +type ListIpSetResult struct { + IpSets []IpSet `json:"ipSets"` + Marker string `json:"marker"` + IsTruncated bool `json:"isTruncated"` + NextMarker string `json:"nextMarker"` + MaxKeys int `json:"maxKeys"` +} + +type GetIpSetDetailResult struct { + IpSetId string `json:"ipSetId"` + Name string `json:"name"` + Description string `json:"description"` + IpVersion string `json:"ipVersion"` + IpAddressInfo []TemplateIpAddressInfo `json:"ipAddressInfo"` + BindedInstances []IpCollectionBindedInstance `json:"bindedInstances"` +} + +type CreateIpGroupArgs struct { + ClientToken string `json:"-"` + Name string `json:"name"` + IpVersion string `json:"ipVersion"` + IpSetIds []string `json:"ipSetIds"` + Description string `json:"description"` +} + +type CreateIpGroupResult struct { + IpGroupId string `json:"ipGroupId"` +} + +type AddIpSet2IpGroupArgs struct { + ClientToken string `json:"-"` + IpSetIds []string `json:"ipSetIds"` +} + +type UnbindIpSetArgs struct { + ClientToken string `json:"-"` + IpSetIds []string `json:"ipSetIds"` +} + +type UpdateIpGroupArgs struct { + ClientToken string `json:"-"` + Name string `json:"name"` + Description string `json:"description"` +} + +type DeleteIpGroupArgs struct { + ClientToken string `json:"-"` +} + +type ListIpGroupArgs struct { + IpVersion string + Marker string + MaxKeys int +} + +type ListIpGroupResult struct { + IpGroups []IpGroup `json:"ipGroups"` + Marker string `json:"marker"` + IsTruncated bool `json:"isTruncated"` + NextMarker string `json:"nextMarker"` + MaxKeys int `json:"maxKeys"` +} + +type GetIpGroupDetailResult struct { + IpGroupId string `json:"ipGroupId"` + Name string `json:"name"` + Description string `json:"description"` + IpVersion string `json:"ipVersion"` + IpSetIds []string `json:"ipSetIds"` + BindedInstances []IpCollectionBindedInstance `json:"bindedInstances"` +} diff --git a/services/vpc/template.go b/services/vpc/template.go new file mode 100644 index 00000000..63899edc --- /dev/null +++ b/services/vpc/template.go @@ -0,0 +1,232 @@ +package vpc + +import ( + "fmt" + "github.com/baidubce/bce-sdk-go/bce" + "github.com/baidubce/bce-sdk-go/http" + "strconv" +) + +func (c *Client) CreateIpSet(args *CreateIpSetArgs) (*CreateIpSetResult, error) { + if args == nil { + return nil, fmt.Errorf("The CreateIpSetArgs cannot be nil.") + } + result := &CreateIpSetResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSet()). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + WithResult(result). + Do() + return result, err +} + +func (c *Client) AddIpAddress2IpSet(ipSetId string, args *AddIpAddress2IpSetArgs) error { + if ipSetId == "" { + return fmt.Errorf("The ipSetId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The AddIpAddress2IpSetArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSetId(ipSetId)+"/ipAddress"). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) DeleteIpAddress(ipSetId string, args *DeleteIpAddressArgs) error { + if ipSetId == "" { + return fmt.Errorf("The ipSetId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The DeleteIpAddressArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSetId(ipSetId)+"/deleteIpAddress"). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) UpdateIpSet(ipSetId string, args *UpdateIpSetArgs) error { + if ipSetId == "" { + return fmt.Errorf("The ipSetId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The UpdateIpSet cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSetId(ipSetId)). + WithMethod(http.PUT). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + WithQueryParam("modifyAttribute", ""). + Do() + return err +} + +func (c *Client) DeleteIpSet(ipSetId string, args *DeleteIpSetArgs) error { + if ipSetId == "" { + return fmt.Errorf("The ipSetId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The DeleteIpSetArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSetId(ipSetId)). + WithMethod(http.DELETE). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) ListIpSet(args *ListIpSetArgs) (*ListIpSetResult, error) { + if args == nil { + args = &ListIpSetArgs{} + } + if args.MaxKeys == 0 { + args.MaxKeys = 1000 + } + result := &ListIpSetResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSet()). + WithMethod(http.GET). + WithQueryParamFilter("ipVersion", args.IpVersion). + WithQueryParamFilter("marker", args.Marker). + WithQueryParamFilter("maxKeys", strconv.Itoa(args.MaxKeys)). + WithResult(result). + Do() + return result, err +} + +func (c *Client) GetIpSetDetail(ipSetId string) (*GetIpSetDetailResult, error) { + if ipSetId == "" { + return nil, fmt.Errorf("The ipSetId cannot be blank.") + } + result := &GetIpSetDetailResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpSetId(ipSetId)). + WithMethod(http.GET). + WithResult(result). + Do() + return result, err +} + +func (c *Client) CreateIpGroup(args *CreateIpGroupArgs) (*CreateIpGroupResult, error) { + if args == nil { + return nil, fmt.Errorf("The CreateIpGroupArgs cannot be nil.") + } + result := &CreateIpGroupResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroup()). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + WithResult(result). + Do() + return result, err +} + +func (c *Client) AddIpSet2IpGroup(ipGroupId string, args *AddIpSet2IpGroupArgs) error { + if ipGroupId == "" { + return fmt.Errorf("The ipGroupId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The AddIpSet2IpGroupArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroupId(ipGroupId)+"/bindIpSet"). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) UnbindIpSet(ipGroupId string, args *UnbindIpSetArgs) error { + if ipGroupId == "" { + return fmt.Errorf("The ipGroupId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The UnbindIpSetArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroupId(ipGroupId)+"/unbindIpSet"). + WithMethod(http.POST). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) UpdateIpGroup(ipGroupId string, args *UpdateIpGroupArgs) error { + if ipGroupId == "" { + return fmt.Errorf("The ipGroupId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The UpdateIpGroupArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroupId(ipGroupId)). + WithMethod(http.PUT). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + WithQueryParam("modifyAttribute", ""). + Do() + return err +} + +func (c *Client) DeleteIpGroup(ipGroupId string, args *DeleteIpGroupArgs) error { + if ipGroupId == "" { + return fmt.Errorf("The ipGroupId cannot be blank.") + } + if args == nil { + return fmt.Errorf("The DeleteIpGroupArgs cannot be nil.") + } + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroupId(ipGroupId)). + WithMethod(http.DELETE). + WithBody(args). + WithQueryParamFilter("clientToken", args.ClientToken). + Do() + return err +} + +func (c *Client) ListIpGroup(args *ListIpGroupArgs) (*ListIpGroupResult, error) { + if args == nil { + args = &ListIpGroupArgs{} + } + if args.MaxKeys == 0 { + args.MaxKeys = 1000 + } + result := &ListIpGroupResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroup()). + WithMethod(http.GET). + WithQueryParamFilter("ipVersion", args.IpVersion). + WithQueryParamFilter("marker", args.Marker). + WithQueryParamFilter("maxKeys", strconv.Itoa(args.MaxKeys)). + WithResult(result). + Do() + return result, err +} + +func (c *Client) GetIpGroupDetail(ipGroupId string) (*GetIpGroupDetailResult, error) { + if ipGroupId == "" { + return nil, fmt.Errorf("The ipGroupId cannot be blank.") + } + result := &GetIpGroupDetailResult{} + err := bce.NewRequestBuilder(c). + WithURL(getURLForIpGroupId(ipGroupId)). + WithMethod(http.GET). + WithResult(result). + Do() + return result, err +}