Reputation: 141
is there anyway to enable IAM API through python. However, I dont see any methods mentioned in Google documentaion. I have gone through this link https://cloud.google.com/service-usage/docs/enable-disable#gcloud but it only describes enabling service API via, gcloud or curl.
Is there anyway I can enable it via Python?
Upvotes: 0
Views: 284
Reputation: 81336
The API you want to use is Service Usage
Link to the REST API:
Link to the Python API:
Example code that I wrote to use the Python API to list services:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
# https://cloud.google.com/service-usage/docs/reference/rest/v1/services
# https://cloud.google.com/service-usage/docs/list-services
credentials = GoogleCredentials.get_application_default()
project = 'projects/development-xxxxxx'
service = discovery.build('serviceusage', 'v1', credentials=credentials)
next = None
totalCount = 0
while 1:
request = service.services().list(parent=project, pageToken=next)
response = ''
try:
response = request.execute()
except Exception as e:
print(e)
break
services = response.get('services')
for index in range(len(services)):
totalCount += 1
item = services[index]
name = item['config']['name']
state = item['state']
print("%-50s %s" % (name, state))
next = response.get('nextPageToken')
# print('NEXT:', next)
if next == None:
break;
print('')
print('Total number of services:', totalCount)
To enable a service call the enable method:
Upvotes: 2