获取镜像列表
更新时间:
接口
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源码:
import timeimport batchcomputefrom batchcompute import CN_SHENZHEN as REGIONfrom batchcompute import Client, ClientErrorACCESS_KEY_ID = 'Your Access Key Id'ACCESS_KEY_SECRET = 'Your Access Key Secret'client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)def list_images():try:marker = ""max_item = 2image_cnt = 0image_type = '' #'System'while 1:response = client.list_images(marker, max_item, image_type)marker = response.NextMarkerimage_cnt += len(response.Items)for image in response.Items:print (image.Id, image.Platform)if marker.strip() == '':breakprint 'Total images: ', image_cntexcept ClientError, e:print (e.get_status_code(), e.get_code(), e.get_requestid(), e.get_msg())if __name__ == '__main__':list_images()
上面例子是获取自定义镜像的列表,如您需要获取官方镜像,请修改 image_type 为 ‘System’。
执行结果:
img-6ki7te6grlhbv42kn8a000 : Windowsimg-6ki7te6grlhbv42kn8a001 : Linuximg-6ki7te6grlhbv42kn8a002 : Windowsimg-6ki7te6grlhbv42kn8a003 : Windowsimg-6kie8e832lnov8gg50k004 : Linuximg-6kir9pdp2lg6220g418000 : WindowsTotal images: 6
该文章对您有帮助吗?