文档

获取镜像列表

更新时间:

接口

list_images

参数

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

返回值

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

属性 类型 描述
NextMarker string 下一页起始资源标识符, 最后一页该值为空。
Items list Image类型的列表

例子

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_images():
  9. try:
  10. marker = ""
  11. max_item = 2
  12. image_cnt = 0
  13. image_type = '' #'System'
  14. while 1:
  15. response = client.list_images(marker, max_item, image_type)
  16. marker = response.NextMarker
  17. image_cnt += len(response.Items)
  18. for image in response.Items:
  19. print (image.Id, image.Platform)
  20. if marker.strip() == '':
  21. break
  22. print 'Total images: ', image_cnt
  23. except ClientError, e:
  24. print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())
  25. if __name__ == '__main__':
  26. list_images()

上面例子是获取自定义镜像的列表,如您需要获取官方镜像,请修改 image_type 为 ‘System’。

执行结果:

  1. img-6ki7te6grlhbv42kn8a000 : Windows
  2. img-6ki7te6grlhbv42kn8a001 : Linux
  3. img-6ki7te6grlhbv42kn8a002 : Windows
  4. img-6ki7te6grlhbv42kn8a003 : Windows
  5. img-6kie8e832lnov8gg50k004 : Linux
  6. img-6kir9pdp2lg6220g418000 : Windows
  7. Total images: 6
  • 本页导读 (0)
文档反馈