Reserved Instance
Updated at:2025-10-20
Query reserved instance list
You can query the reserved instance list with the following code
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc/api"
5 "github.com/baidubce/bce-sdk-go/services/bcc"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 // Create a BCC client
11 client, _ := bcc.NewClient(ak, sk, endpoint)
12 args := &api.ListReservedInstanceArgs{
13 ZoneName: "cn-bj-a",
14 MaxKeys: 10,
15 Marker: "r-*****",
16 }
17 result, err := client.ListReservedInstances(args)
18 if err != nil {
19 panic(err)
20 }
21 fmt.Println(result)
22}
Create reserved instances
You can create reserved instances with the following code
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc/api"
5 "github.com/baidubce/bce-sdk-go/services/bcc"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 // Create a BCC client
11 client, _ := bcc.NewClient(ak, sk, endpoint)
12 args := &api.CreateReservedInstanceArgs{
13 ClientToken: "myClientToken",
14 ReservedInstanceName: "myReservedInstance",
15 Scope: "AZ",
16 ZoneName: "cn-bj-a",
17 Spec: "bcc.g5.c2m8",
18 OfferingType: "FullyPrepay",
19 InstanceCount: 1,
20 ReservedInstanceCount: 1,
21 ReservedInstanceTime: 365,
22 ReservedInstanceTimeUnit: "month",
23 AutoRenewTimeUnit: "month",
24 AutoRenewTime: 1,
25 AutoRenew: true,
26 Tags: []api.Tag{
27 {
28 TagKey: "Env",
29 TagValue: "Production",
30 },
31 },
32 EhcClusterId: "ehcCluster123",
33 TicketId: "ticket456",
34 }
35 result, err := client.CreateReservedInstance(args)
36 if err != nil {
37 panic(err)
38 }
39 fmt.Println(result)
40}
Modify reserved instances
You can modify reserved instance attributes with the following code
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc"
5 "github.com/baidubce/bce-sdk-go/services/bcc/api"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 // Create a BCC client
11 client, _ := bcc.NewClient(ak, sk, endpoint)
12 args := &api.ModifyReservedInstancesArgs{
13 ReservedInstances: []api.ModifyReservedInstance{
14 {
15 ReservedInstanceId: "r-UBVQFB5b",
16 ReservedInstanceName: "update-reserved-instance",
17 },
18 },
19 }
20 result, err := client.ModifyReservedInstances(args)
21 if err != nil {
22 panic(err)
23 }
24 fmt.Println(result)
25}
Tag unbinding
You can bind a tag to a specified reserved instance with the following code
Go
1package main
2import (
3 "github.com/baidubce/bce-sdk-go/model"
4 "github.com/baidubce/bce-sdk-go/services/bcc/api"
5 "github.com/baidubce/bce-sdk-go/services/bcc"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 client, _ := bcc.NewClient(ak, sk, endpoint) // Create a BCC Client
11 args := &api.ReservedTagsRequest{
12 // Tag list
13 ChangeTags: []model.TagModel{
14 {
15 TagKey: "TagKey-go",
16 TagValue: "TagValue",
17 },
18 },
19 // List of reserved instance IDs, maximum 100
20 ReservedInstanceIds: []string{
21 "r-oFpMXKhv", "r-HrztSVk0",
22 },
23 }
24 err := client.BindReservedInstanceToTags(args)
25 if err != nil {
26 panic(err)
27 }
28}
Unbind tags
You can unbind the tag from a specified reserved instance with the following code
Go
1package main
2import (
3 "github.com/baidubce/bce-sdk-go/model"
4 "github.com/baidubce/bce-sdk-go/services/bcc/api"
5 "github.com/baidubce/bce-sdk-go/services/bcc"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 client, _ := bcc.NewClient(ak, sk, endpoint) // Create a BCC Client
11 args := &api.ReservedTagsRequest{
12 // Tag list
13 ChangeTags: []model.TagModel{
14 {
15 TagKey: "TagKey-go",
16 TagValue: "TagValue",
17 },
18 },
19 // List of reserved instance IDs, maximum 100
20 ReservedInstanceIds: []string{
21 "r-oFpMXKhv", "r-HrztSVk0",
22 },
23 }
24 err := client.UnbindReservedInstanceFromTags(args)
25 if err != nil {
26 panic(err)
27 }
28}
Renew reserved instances
You can renew reserved instances with the following code
Go
1package main
2import (
3 "fmt"
4 "github.com/baidubce/bce-sdk-go/services/bcc/api"
5 "github.com/baidubce/bce-sdk-go/services/bcc"
6)
7func main() {
8 // Initialize AK/SK/Endpoint
9 ak, sk, endpoint := "ak", "sk", "bcc.bj.baidubce.com"
10 // Create a BCC client
11 client, _ := bcc.NewClient(ak, sk, endpoint)
12 args := &api.RenewReservedInstancesArgs{
13 // Client Token
14 ClientToken: "myClientToken",
15 // Reserved instance IDs
16 ReservedInstanceIds: []string{
17 "test-renew",
18 },
19 // Renewal period of reserved instance, supporting 3, 6, 9, 12, 24 and 36 months
20 ReservedInstanceTime: 1,
21 // Purchase period unit of reserved instance, defaulting to month. It cannot be changed
22 ReservedInstanceTimeUnit: "month",
23 // Auto-renewal period unit of reserved instance, defaulting to month. It cannot be changed
24 AutoRenewTimeUnit: "month",
25 // Auto-renewal period of reserved instance, supporting 3, 6, 9, 12, 24 and 36 months. It is required and must be consistent with reservedInstanceTime when autoRenew is true
26 AutoRenewTime: 1,
27 // Auto-renewal switch. Default: false
28 AutoRenew: true,
29 }
30 result, err := client.RenewReservedInstances(args)
31 if err != nil {
32 panic(err)
33 }
34 fmt.Println(result)
35}
