I am trying to extract cost of our GCP cloud using api. As a first step, I am just trying to extract list of instances in given zone. However I get following only, without instances information:
XXX-MBP:gcp XXX$ gcloud beta auth application-default login Your browser has been opened to visit:
Credentials saved to file: [/Users/XXX/.config/gcloud/application_default_credentials.json]
These credentials will be used by any library that requests Application Default Credentials.
To generate an access token for other uses, run: gcloud auth application-default print-access-token XXX-MBP:gcp XXX$
My code is as follows
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)
I was expecting list of vm in my account.
Can someone help please?