Reserved Instance
Updated at:2025-10-20
Create reserved instances
You can create reserved instances with the following code
Python
1from baidubce.services.bcc import bcc_model
2from baidubce.services.bcc.bcc_client import BccClient
3from sample.bcc import bcc_sample_conf
4if __name__ == "__main__":
5 import logging
6 logging.basicConfig(level=logging.DEBUG)
7 __logger = logging.getLogger(__name__)
8 bcc_client = BccClient(bcc_sample_conf.config)
9 response = bcc_client.create_reserved_instances(reserved_instance_name="test_create_reserved_instances",
10 scope="AZ",
11 zone_name="cn-bj-a",
12 spec="bcc.g5.c2m8",
13 offering_type="FullyPrepay",
14 instance_count=1,
15 reserved_instance_count=1,
16 reserved_instance_time=1,
17 reserved_instance_time_unit="month",
18 auto_renew_time_unit="month",
19 auto_renew_time=1,
20 auto_renew=True,
21 tags=[bcc_model.TagModel("k1", "v1")])
22# Print returned result
23 print(response)
Adjust reserved instance
You can adjust reserved instances with the following code
Python
1from baidubce.services.bcc import bcc_model
2from baidubce.services.bcc.bcc_client import BccClient
3from sample.bcc import bcc_sample_conf
4if __name__ == "__main__":
5 import logging
6 logging.basicConfig(level=logging.DEBUG)
7 __logger = logging.getLogger(__name__)
8 bcc_client = BccClient(bcc_sample_conf.config)
9 reserved_instance = bcc_model.ModifyReservedInstanceModel(reservedInstanceId='r-UBVQFB5b',
10 reservedInstanceName='rename-reservedInstanceName')
11 reserved_instances_list = [reserved_instance]
12 response = bcc_client.modify_reserved_instances(reserved_instances=reserved_instances_list)
13# Print returned result
14 print(response)
Tag unbinding
You can bind a tag to a specified reserved instance with the following code
Python
1from baidubce.services.bcc import bcc_model
2from baidubce.services.bcc.bcc_client import BccClient
3from sample.bcc import bcc_sample_conf
4if __name__ == "__main__":
5 import logging
6 logging.basicConfig(level=logging.DEBUG)
7 __logger = logging.getLogger(__name__)
8 bcc_client = BccClient(bcc_sample_conf.config)
9# Reserved instance IDs, maximum 100
10 reserved_instance_ids = ['r-Qyycx1SX']
11 instance_tag1 = bcc_model.TagModel(tagKey='TestKey02',
12 tagValue='TestValue02')
13 instance_tag2 = bcc_model.TagModel(tagKey='TestKey03',
14 tagValue='TestValue03')
15# List of tags to be bound
16 instance_tags = [instance_tag1, instance_tag2]
17 bcc_client.bind_reserved_instance_to_tags(reserved_instance_ids=reserved_instance_ids, tags=instance_tags)
Unbind tags
You can unbind the tag from a specified reserved instance with the following code
Python
1from baidubce.services.bcc import bcc_model
2from baidubce.services.bcc.bcc_client import BccClient
3from sample.bcc import bcc_sample_conf
4if __name__ == "__main__":
5 import logging
6 logging.basicConfig(level=logging.DEBUG)
7 __logger = logging.getLogger(__name__)
8 bcc_client = BccClient(bcc_sample_conf.config)
9# Reserved instance IDs, maximum 100
10 reserved_instance_ids = ['r-Qyycx1SX']
11 instance_tag1 = bcc_model.TagModel(tagKey='TestKey02',
12 tagValue='TestValue02')
13 instance_tag2 = bcc_model.TagModel(tagKey='TestKey03',
14 tagValue='TestValue03')
15# List of tags to be unbound
16 instance_tags = [instance_tag1, instance_tag2]
17 bcc_client.unbind_reserved_instance_from_tags(reserved_instance_ids=reserved_instance_ids, tags=instance_tags)
