弹性保障
更新时间:2026-10-20
弹性保障是一种容量确定性保障服务:在真正创建实例之前,提前锁定指定地域、可用区、实例规格和数量的计算资源,形成用户可使用的私有资源池。后续创建按量实例时,可优先或强制从该私有资源池中分配资源,以提升实例交付确定性。
创建弹性保障
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client, bcc_model
4
5if __name__ == '__main__':
6 # 设置您的ak、sk和要访问的地域
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12 client = bcc_client.BccClient(config)
13
14 response = client.create_elasticity_assurance(
15 zone_name='cn-bj-a', # 逻辑可用区,单个保障仅支持一个可用区
16 spec='bcc.g5.c4m16', # 需要保障的BCC实例规格
17 capacity=10, # 保障容量,单位为实例台数,取值1~100
18 period=6, # 购买时长,单位为月,允许值:1~9、12、24、36、48、60
19 elasticity_assurance_name='promotion-pool', # 可选,弹性保障名称。字母/数字/中文及-_/.,必须以中文或字母开头,长度1~65
20 tags=[bcc_model.TagModel('business', 'promotion')], # 可选,标签列表
21 auto_renew=True, # 可选,是否开启自动续费
22 )
23 # 返回体包含 requestId、orderId、elasticityAssuranceIds(List)
24 print(response)
-
必传参数:
- 可用区 zone_name
- 实例规格 spec
- 保障容量 capacity
- 购买时长 period
查询弹性保障列表
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4
5if __name__ == '__main__':
6 # 设置您的ak、sk和要访问的地域
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12 client = bcc_client.BccClient(config)
13
14 response = client.list_elasticity_assurances(
15 elasticity_assurance_ids=['ea-Ab12Cd34'], # 可选,弹性保障ID列表,精确匹配,最多100个
16 elasticity_assurance_name='promotion', # 可选,弹性保障名称,最左前缀匹配
17 spec='bcc.g5.c4m16', # 可选,实例规格,最左前缀匹配
18 status=['ACTIVE'], # 可选,状态列表,可选值 CREATING / ACTIVE / EXPIRED
19 zone_name='cn-bj-a', # 可选,逻辑可用区
20 marker='', # 可选,批量获取列表查询的起始位置
21 max_keys=100, # 可选,每页包含的最大数量,最大值1000
22 )
23 # 返回体包含 requestId、isTruncated、nextMarker、maxKeys、elasticityAssurances(List)
24 # 每个弹性保障含 elasticityAssuranceId、spec、status、zoneName、capacity、
25 # usedCapacity(已匹配实例数)、availableCapacity(剩余容量)、createTime、expireTime、
26 # autoRenew、autoRenewPeriod、tags、instances(当前关联的按量实例列表)
27 print(response)
退订弹性保障
按剩余周期退款,并释放资源池内剩余的预留实例。
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4
5if __name__ == '__main__':
6 # 设置您的ak、sk和要访问的地域
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12 client = bcc_client.BccClient(config)
13
14 response = client.release_elasticity_assurance(
15 elasticity_assurance_ids=['ea-Ab12Cd34'], # 待释放的弹性保障ID列表,单次最多100个
16 )
17 print(response)
续费弹性保障
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4
5if __name__ == '__main__':
6 # 设置您的ak、sk和要访问的地域
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12 client = bcc_client.BccClient(config)
13
14 response = client.renew_elasticity_assurances(
15 elasticity_assurance_ids=['ea-Ab12Cd34'], # 弹性保障ID列表,单次最多100个
16 period=12, # 续费时长,单位为月,允许值:1~9、12、24、36、48、60
17 )
18
19 # 注意:仅当弹性保障处于 ACTIVE 状态时可续费
20 print(response)
修改弹性保障自动续费属性
Python
1from baidubce.auth.bce_credentials import BceCredentials
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.services.bcc import bcc_client
4
5if __name__ == '__main__':
6 # 设置您的ak、sk和要访问的地域
7 HOST = b'http://bcc.bj.baidubce.com'
8 AK = b'ak'
9 SK = b'sk'
10 config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
11 endpoint=HOST)
12 client = bcc_client.BccClient(config)
13
14 # 开启或修改自动续费
15 response = client.modify_elasticity_assurance_auto_renew(
16 elasticity_assurance_ids=['ea-Ab12Cd34'], # 弹性保障ID列表,单次最多100个
17 auto_renew=True, # True:开启或修改自动续费;False:取消自动续费
18 auto_renew_period=12, # auto_renew=True时必填,单位为月,允许值:1~9、12、24、36、48、60
19 )
20 print(response)
21
22 # 取消自动续费时无需传 auto_renew_period
23 # response = client.modify_elasticity_assurance_auto_renew(
24 # elasticity_assurance_ids=['ea-Ab12Cd34'],
25 # auto_renew=False,
26 # )
27 # print(response)
评价此篇文章
