部署集
更新时间:2024-07-02
创建部署集
通过以下代码可以依据给定的创建参数创建部署集:
# !/usr/bin/env python
# coding=utf-8
from baidubce.services.bcc import bcc_client
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
response = client.create_deploy_set(name="your deploy set name", # 部署集名称,非必填项
strategy="HOST_HA", # 部署集策略,非必填项,默认值为HOST_HA,可选值为:HOST_HA、RACK_HA、TOR_HA
concurrency=5, # 部署集并发度,非必填项,默认值为1
desc="your deploy set description") # 部署集描述,非必填项
print(response)
查询部署集列表
通过以下代码可以查询所有部署集实例的列表及详情信息:
# !/usr/bin/env python
# coding=utf-8
from baidubce.services.bcc import bcc_client
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 请求查询部署集列表,返回账号全量部署集信息
response = client.list_deploy_sets()
print(response)
修改部署集属性
使用以下代码可以修改指定部署集的指定属性值:
# !/usr/bin/env python
# coding=utf-8
from baidubce.services.bcc import bcc_client
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
response = client.modify_deploy_set(deploy_set_id='dset-******', # 部署集ID, 必填项
name="modify-new-name", # 部署集名称,非必填项
desc="modify new description") # 部署集描述,非必填项
print(response)
删除指定的部署集
使用以下代码删除用户自己的指定的部署集:
# !/usr/bin/env python
# coding=utf-8
from baidubce.services.bcc import bcc_client
from baidubce.auth.bce_credentials import BceCredentials
from baidubce.bce_client_configuration import BceClientConfiguration
if __name__ == '__main__':
# 设置您的ak、sk和要访问的地域
HOST = b'http://bcc.bj.baidubce.com'
AK = b'ak'
SK = b'sk'
# 设置默认配置
config = BceClientConfiguration(credentials=BceCredentials(AK, SK),
endpoint=HOST)
# 创建bcc client
client = bcc_client.BccClient(config)
# 请求删除部署集
response = client.delete_deploy_set(deploy_set_id='dset-*******') # 部署集ID,必填项
print(response)
绑定指定的部署集
使用以下代码绑用户自己指定的部署集:
def test_update_instance_deploy(self):
"""
test case for update_instance_deploy
"""
resp = self.client.update_instance_deploy(instance_id='iid1', deployset_id_list=['did1', 'did2'], force=True)
self.assertEqual(
type(resp),
baidubce.bce_response.BceResponse)
if resp is not None and resp.content is not None:
print(json.loads(resp.content.decode('utf-8')))
else:
print(resp)
解绑指定的部署集
使用以下代码解绑用户自己指定的部署集:
def test_del_instance_deploy(self):
"""
test case for del_instance_deploy
"""
resp = self.client.del_instance_deploy(instance_id_list=['iid1', 'iid2'], deploy_set_id='dsid')
self.assertEqual(
type(resp),
baidubce.bce_response.BceResponse)
if resp is not None and resp.content is not None:
print(json.loads(resp.content.decode('utf-8')))
else:
print(resp)