预留实例券
更新时间:2024-11-07
查询预留实例券列表
使用以下代码查询预留实例券列表
package main
import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/bcc"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
// 创建BCC Client
client, _ := bcc.NewClient(ak, sk, endpoint)
args := &api.ListReservedInstanceArgs{
ZoneName: "cn-bj-a",
MaxKeys: 10,
Marker: "r-*****",
}
result, err := client.ListReservedInstances(args)
if err != nil {
panic(err)
}
fmt.Println(result)
}
创建预留实例券
使用以下代码创建预留实例券
package main
import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/bcc"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
// 创建BCC Client
client, _ := bcc.NewClient(ak, sk, endpoint)
args := &api.CreateReservedInstanceArgs{
ClientToken: "myClientToken",
ReservedInstanceName: "myReservedInstance",
Scope: "AZ",
ZoneName: "cn-bj-a",
Spec: "bcc.g5.c2m8",
OfferingType: "FullyPrepay",
InstanceCount: 1,
ReservedInstanceCount: 1,
ReservedInstanceTime: 365,
ReservedInstanceTimeUnit: "month",
AutoRenewTimeUnit: "month",
AutoRenewTime: 1,
AutoRenew: true,
Tags: []api.Tag{
{
TagKey: "Env",
TagValue: "Production",
},
},
EhcClusterId: "ehcCluster123",
TicketId: "ticket456",
}
result, err := client.CreateReservedInstance(args)
if err != nil {
panic(err)
}
fmt.Println(result)
}
修改预留实例券
使用以下代码修改预留实例券属性
package main
import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/bcc"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
// 创建BCC Client
client, _ := bcc.NewClient(ak, sk, endpoint)
args := &api.ModifyReservedInstancesArgs{
ReservedInstances: []api.ModifyReservedInstance{
{
ReservedInstanceId: "r-UBVQFB5b",
ReservedInstanceName: "update-reserved-instance",
},
},
}
result, err := client.ModifyReservedInstances(args)
if err != nil {
panic(err)
}
fmt.Println(result)
}
绑定标签
使用以下代码给指定预留实例券绑定标签
package main
import (
"github.com/baidubce/bce-sdk-go/model"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/bcc"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client
args := &api.ReservedTagsRequest{
// 标签列表
ChangeTags: []model.TagModel{
{
TagKey: "TagKey-go",
TagValue: "TagValue",
},
},
// 预留实例券id列表,最多支持100个
ReservedInstanceIds: []string{
"r-oFpMXKhv", "r-HrztSVk0",
},
}
err := client.BindReservedInstanceToTags(args)
if err != nil {
panic(err)
}
}
解绑标签
使用以下代码从指定预留实例券中解绑标签
package main
import (
"github.com/baidubce/bce-sdk-go/model"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/bcc"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
client, _ := bcc.NewClient(ak, sk, endpoint) // 创建BCC Client
args := &api.ReservedTagsRequest{
// 标签列表
ChangeTags: []model.TagModel{
{
TagKey: "TagKey-go",
TagValue: "TagValue",
},
},
// 预留实例券id列表,最多支持100个
ReservedInstanceIds: []string{
"r-oFpMXKhv", "r-HrztSVk0",
},
}
err := client.UnbindReservedInstanceFromTags(args)
if err != nil {
panic(err)
}
}
续费预留实例券
使用以下代码续费预留实例券
package main
import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/bcc/api"
"github.com/baidubce/bce-sdk-go/services/bcc"
)
func main() {
// 初始化AK/SK/Endpoint
ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
// 创建BCC Client
client, _ := bcc.NewClient(ak, sk, endpoint)
args := &api.RenewReservedInstancesArgs{
// 客户端Token
ClientToken: "myClientToken",
// 预留实例券ids
ReservedInstanceIds: []string{
"test-renew",
},
// 预留实例券续费时长,支持3,6,9,12,24,36个月
ReservedInstanceTime: 1,
// 预留实例券购买时长单位,默认为month,不可变更
ReservedInstanceTimeUnit: "month",
// 预留实例券自动续费时长单位,默认为month,不可变更
AutoRenewTimeUnit: "month",
// 预留实例券自动续费时长,支持3,6,9,12,24,36个月,autoRenew为true时,必选且必须与reservedInstanceTime一致
AutoRenewTime: 1,
// 自动续费开关,默认为false
AutoRenew: true,
}
result, err := client.RenewReservedInstances(args)
if err != nil {
panic(err)
}
fmt.Println(result)
}