首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用gcloud python api获取实例镜像名称

使用gcloud python api获取实例镜像名称
EN

Stack Overflow用户
提问于 2019-01-11 23:25:48
回答 1查看 147关注 0票数 1

如何通过python中的gcloud计算引擎API来检索实例的镜像名称?

列出我的实例时

代码语言:javascript
复制
compute.instances().list(project=project, zone=zone , filter ='status eq '+ instance_status).execute()

响应没有给出实例镜像名称(debian-9)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-15 00:15:09

要使用Python API获取源镜像,请使用以下请求:

代码语言:javascript
复制
request = service.disks().get(project=project, zone=zone, disk=disk)
response = request.execute()

输出体具有'sourceImage'字段以获取更多信息,请参见公共documentation以及参见下面的示例:

代码语言:javascript
复制
from pprint import pprint

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

service = discovery.build('compute', 'v1', credentials=credentials)

# Project ID for this request.
project = 'my-project'  # TODO: Update placeholder value.

# The name of the zone for this request.
zone = 'my-zone'  # TODO: Update placeholder value.

# Name of the persistent disk to return.
disk = 'my-disk'  # TODO: Update placeholder value.

request = service.disks().get(project=project, zone=zone, disk=disk)
response = request.execute()

# TODO: Change code below to process the `response` dict:
pprint(response)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54149420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档