0

我正在尝试使用 api 提取我们的 GCP 云的成本。作为第一步,我只是试图提取给定区域中的实例列表。但是我只得到以下信息,没有实例信息:

XXX-MBP:gcp XXX$ gcloud beta auth application-default login 你的浏览器已经打开访问:

https://accounts.google.com/o/oauth2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&prompt=select_account&response_type=code&client_id=XXX-XXX.apps.googleusercontent.com&scope=https%3A%2F% 2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&access_type=offline

凭据保存到文件:[/Users/XXX/.config/gcloud/application_default_credentials.json]

任何请求应用程序默认凭据的库都将使用这些凭据。

要为其他用途生成访问令牌,请运行: gcloud auth application-default print-access-token XXX-MBP:gcp XXX$

我的代码如下

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 = 'XXX'  # TODO: Update placeholder value.

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

request = service.instances().list(project=project, zone=zone)
while request is not None:
    response = request.execute()

    for instance in response['items']:
        # TODO: Change code below to process each `instance` resource:
        pprint(instance)

    request = service.instances().list_next(previous_request=request, previous_response=response)

我在我的帐户中期待 vm 列表。

有人可以帮忙吗?

4

0 回答 0