文档

获取集群实例列表

接口

list_cluster_instances

参数

属性 类型 是否必须 描述
cluster_id string 集群标识符
group_name string 实例组名称
next_marker string 下一页起始资源标识符, 最后一页该值为空。
max_item_count int 实际返回最大资源数量。默认值50,最大值100。

返回值

list_cluster_instances方法返回一个 ListResponse 对象,包含了ClusterInstance对象的集合。请参阅ClusterInstance类的描述,了解ClusterInstance对象的属性。

例子

Python 源码:

  1. import time
  2. import batchcompute
  3. from batchcompute import CN_SHENZHEN as REGION
  4. from batchcompute import Client, ClientError
  5. ACCESS_KEY_ID = 'Your Access Key Id'
  6. ACCESS_KEY_SECRET = 'Your Access Key Secret'
  7. client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)
  8. def list_cluster_instances():
  9. try:
  10. cluster_id = "cls-xxx"
  11. group_name = "group1"
  12. marker = ""
  13. max_item = 10
  14. instances_cnt = 0
  15. while 1:
  16. response = client.list_cluster_instances(cluster_id, group_name, marker, max_item)
  17. marker = response.NextMarker
  18. instances_cnt += len(response.Items)
  19. for cluster_instance in response.Items:
  20. print cluster_instance.Id, ' : ', cluster_instance.IpAddress
  21. if marker.strip() == '':
  22. break
  23. print 'Total instances: ', instances_cnt
  24. except ClientError, e:
  25. print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())
  26. if __name__ == '__main__':
  27. list_cluster_instances()

我们仅仅打印了实例标识符和实例 IP ,如您需要获取更多信息请参与 API 的属性说明。

执行结果:

  1. ins-6kial5tfblm09er5bt2000 : 10.169.88.18
  2. ins-6kial5tfclm09er5bt2000 : 10.44.79.90
  3. ins-6kial5tfdlm09er5bt2000 : 10.44.64.219
  4. ins-6kial5tfelm09er5bt2000 : 10.44.85.53
  5. ins-6kial5tfflm09er5bt2000 : 10.44.80.88
  6. ins-6kial5tfglm09er5bt2000 : 10.44.72.6
  7. ins-6kial5tfhlm09er5bt2000 : 10.44.82.125
  8. ins-6kial5tfilm09er5bt2000 : 10.169.88.222
  9. ins-6kial5tfjlm09er5bt2000 : 10.44.82.2
  10. Total instances: 9
  • 本页导读 (0)
文档反馈