InstanceGroup(实例组)
更新时间:2022-05-18
查询实例组列表
如下代码可根据集群ID获取其实例组信息:
try:
response = bmr_client.list_instance_groups(cluster_id)
for instance_group in response.instance_groups:
LOG.debug('list instance groups %s: %s' % (instance_group.id, instance_group))
except BceHttpClientError as e:
if isinstance(e.last_error, BceServerError):
LOG.error('list_instance_groups failed. Response %s, code: %s, msg: %s'
% (e.last_error.status_code, e.last_error.code, e.last_error.args))
else:
LOG.error('list_instance_groups failed. Unknown exception: %s' % e)
修改实例组配置
BMR支持对CORE、TASK节点进行配置变更,示例代码如下:
try:
instance_group_config_core = instancegroup_config(core_instance_id, core_instance_count + 1)
instance_group_config_task = instancegroup_config(task_instance_id, task_instance_count + 1)
instance_group_config_client = instancegroup_config(client_instance_id, client_instance_count + 1)
bmr_client.scale_cluster(cluster_id, instance_group_config=[instance_group_config_core, instance_group_config_task, instance_group_config_client])
except BceHttpClientError as e:
if isinstance(e.last_error, BceServerError):
LOG.error('scale_cluster failed. Response %s, code: %s, msg: %s'
% (e.last_error.status_code, e.last_error.code, e.last_error.args))
else:
LOG.error('scale_cluster failed. Unknown exception: %s' % e)