预留实例券
更新时间:2024-07-02
创建预留实例券
使用以下代码创建预留实例券
from baidubce.services.bcc import bcc_model
from baidubce.services.bcc.bcc_client import BccClient
from sample.bcc import bcc_sample_conf
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
__logger = logging.getLogger(__name__)
bcc_client = BccClient(bcc_sample_conf.config)
response = bcc_client.create_reserved_instances(reserved_instance_name="test_create_reserved_instances",
scope="AZ",
zone_name="cn-bj-a",
spec="bcc.g5.c2m8",
offering_type="FullyPrepay",
instance_count=1,
reserved_instance_count=1,
reserved_instance_time=1,
reserved_instance_time_unit="month",
auto_renew_time_unit="month",
auto_renew_time=1,
auto_renew=True,
tags=[bcc_model.TagModel("k1", "v1")])
# 打印返回结果
print(response)
调整预留实例券
使用以下代码调整预留实例券
from baidubce.services.bcc import bcc_model
from baidubce.services.bcc.bcc_client import BccClient
from sample.bcc import bcc_sample_conf
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
__logger = logging.getLogger(__name__)
bcc_client = BccClient(bcc_sample_conf.config)
reserved_instance = bcc_model.ModifyReservedInstanceModel(reservedInstanceId='r-UBVQFB5b',
reservedInstanceName='rename-reservedInstanceName')
reserved_instances_list = [reserved_instance]
response = bcc_client.modify_reserved_instances(reserved_instances=reserved_instances_list)
# 打印返回结果
print(response)
绑定标签
使用以下代码给指定预留实例券绑定标签
from baidubce.services.bcc import bcc_model
from baidubce.services.bcc.bcc_client import BccClient
from sample.bcc import bcc_sample_conf
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
__logger = logging.getLogger(__name__)
bcc_client = BccClient(bcc_sample_conf.config)
# 预留实例券ID,最多支持100个
reserved_instance_ids = ['r-Qyycx1SX']
instance_tag1 = bcc_model.TagModel(tagKey='TestKey02',
tagValue='TestValue02')
instance_tag2 = bcc_model.TagModel(tagKey='TestKey03',
tagValue='TestValue03')
# 待绑定tag列表
instance_tags = [instance_tag1, instance_tag2]
bcc_client.bind_reserved_instance_to_tags(reserved_instance_ids=reserved_instance_ids, tags=instance_tags)
解绑标签
使用以下代码从指定预留实例券中解绑标签
from baidubce.services.bcc import bcc_model
from baidubce.services.bcc.bcc_client import BccClient
from sample.bcc import bcc_sample_conf
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.DEBUG)
__logger = logging.getLogger(__name__)
bcc_client = BccClient(bcc_sample_conf.config)
# 预留实例券ID,最多支持100个
reserved_instance_ids = ['r-Qyycx1SX']
instance_tag1 = bcc_model.TagModel(tagKey='TestKey02',
tagValue='TestValue02')
instance_tag2 = bcc_model.TagModel(tagKey='TestKey03',
tagValue='TestValue03')
# 待解绑tag列表
instance_tags = [instance_tag1, instance_tag2]
bcc_client.unbind_reserved_instance_from_tags(reserved_instance_ids=reserved_instance_ids, tags=instance_tags)