LIST method (to handle pagination) (#355)

Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
The Magician 2019-08-16 14:42:12 -07:00 committed by Alex Stephen
parent 1c906b1c2c
commit 0c2b6efe52
61 changed files with 144 additions and 480 deletions

View file

@ -119,6 +119,30 @@ class GcpSession(object):
kwargs.update({'json': body})
return self.full_patch(url, **kwargs)
def list(self, url, callback, params=None, array_name='items',
pageToken='nextPageToken', **kwargs):
"""
This should be used for calling the GCP list APIs. It will return
an array of items
This takes a callback to a `return_if_object(module, response)`
function that will decode the response + return a dictionary. Some
modules handle the decode + error processing differently, so we should
defer to the module to handle this.
"""
resp = callback(self.module, self.full_get(url, params, **kwargs))
items = resp.get(array_name) if resp.get(array_name) else []
while resp.get(pageToken):
if params:
params['pageToken'] = resp.get(pageToken)
else:
params = {'pageToken': resp[pageToken]}
resp = callback(self.module, self.full_get(url, params, **kwargs))
if resp.get(array_name):
items = items + resp.get(array_name)
return items
# The following methods fully mimic the requests API and should be used.
def full_get(self, url, params=None, **kwargs):
kwargs['headers'] = self._set_headers(kwargs.get('headers'))

View file

@ -101,12 +101,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('ingressRules'):
items = items.get('ingressRules')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -116,8 +111,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'appengine')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='ingressRules')
def return_if_object(module, response):

View file

@ -208,12 +208,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/bigquery']
items = fetch_list(module, collection(module))
if items.get('datasets'):
items = items.get('datasets')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -223,8 +218,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'bigquery')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='datasets')
def return_if_object(module, response):

View file

@ -546,12 +546,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/bigquery']
items = fetch_list(module, collection(module))
if items.get('tables'):
items = items.get('tables')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -561,8 +556,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'bigquery')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='tables')
def return_if_object(module, response):

View file

@ -324,12 +324,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('triggers'):
items = items.get('triggers')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -339,8 +334,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'cloudbuild')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='triggers')
def return_if_object(module, response):

View file

@ -224,12 +224,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('functions'):
items = items.get('functions')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -239,8 +234,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'cloudfunctions')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='functions')
def return_if_object(module, response):

View file

@ -311,12 +311,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('jobs'):
items = items.get('jobs')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -326,8 +321,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'cloudscheduler')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='jobs')
def return_if_object(module, response):

View file

@ -216,12 +216,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('queues'):
items = items.get('queues')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -231,8 +226,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'cloudtasks')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='queues')
def return_if_object(module, response):

View file

@ -159,12 +159,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -174,8 +169,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -224,12 +224,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -239,8 +234,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -142,12 +142,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -157,8 +152,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -379,12 +379,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -394,8 +389,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -302,12 +302,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -317,8 +312,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -258,12 +258,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -273,8 +268,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -260,12 +260,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -275,8 +270,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -159,12 +159,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -174,8 +169,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -189,12 +189,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -204,8 +199,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -369,12 +369,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -384,8 +379,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -159,12 +159,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -174,8 +169,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -159,12 +159,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -174,8 +169,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -301,12 +301,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -316,8 +311,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -168,12 +168,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -183,8 +178,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -243,12 +243,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -258,8 +253,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -530,12 +530,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -545,8 +540,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -488,12 +488,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -503,8 +498,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -225,12 +225,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -240,8 +235,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -162,12 +162,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -177,8 +172,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -248,12 +248,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -263,8 +258,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -162,12 +162,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -177,8 +172,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -178,12 +178,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -193,8 +188,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -191,12 +191,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -206,8 +201,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -126,12 +126,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -141,8 +136,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -164,12 +164,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -179,8 +174,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -187,12 +187,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -202,8 +197,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -120,12 +120,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -135,8 +130,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -143,12 +143,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -158,8 +153,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -179,12 +179,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -194,8 +189,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -139,12 +139,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -154,8 +149,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -125,12 +125,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -140,8 +135,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -141,12 +141,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -156,8 +151,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -221,12 +221,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -236,8 +231,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -168,12 +168,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
items = fetch_list(module, collection(module), query_options(module.params['filters']))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
module.exit_json(**return_value)
@ -183,8 +178,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'compute')
response = auth.get(link, params={'filter': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
def query_options(filters):

View file

@ -586,12 +586,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('clusters'):
items = items.get('clusters')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -601,8 +596,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'container')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='clusters')
def return_if_object(module, response):

View file

@ -371,12 +371,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('nodePools'):
items = items.get('nodePools')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -387,8 +382,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'container')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='nodePools')
def return_if_object(module, response):

View file

@ -214,12 +214,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
items = fetch_list(module, collection(module), module.params['dns_name'])
if items.get('managedZones'):
items = items.get('managedZones')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module), module.params['dns_name'])}
module.exit_json(**return_value)
@ -229,8 +224,7 @@ def collection(module):
def fetch_list(module, link, query):
auth = GcpSession(module, 'dns')
response = auth.get(link, params={'dnsName': query})
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='managedZones', params={'dnsName': query})
def return_if_object(module, response):

View file

@ -117,12 +117,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
items = fetch_list(module, collection(module))
if items.get('rrsets'):
items = items.get('rrsets')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -133,8 +128,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'dns')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='rrsets')
def return_if_object(module, response):

View file

@ -112,12 +112,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/iam']
items = fetch_list(module, collection(module))
if items.get('roles'):
items = items.get('roles')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -127,8 +122,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'iam')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='roles')
def return_if_object(module, response):

View file

@ -111,12 +111,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/iam']
items = fetch_list(module, collection(module))
if items.get('accounts'):
items = items.get('accounts')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -126,8 +121,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'iam')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='accounts')
def return_if_object(module, response):

View file

@ -120,12 +120,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('models'):
items = items.get('models')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -135,8 +130,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'mlengine')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='models')
def return_if_object(module, response):

View file

@ -211,12 +211,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('versions'):
items = items.get('versions')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -227,8 +222,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'mlengine')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='versions')
def return_if_object(module, response):

View file

@ -190,12 +190,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
items = fetch_list(module, collection(module))
if items.get('subscriptions'):
items = items.get('subscriptions')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -205,8 +200,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'pubsub')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='subscriptions')
def return_if_object(module, response):

View file

@ -117,12 +117,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
items = fetch_list(module, collection(module))
if items.get('topics'):
items = items.get('topics')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -132,8 +127,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'pubsub')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='topics')
def return_if_object(module, response):

View file

@ -188,12 +188,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('instances'):
items = items.get('instances')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -203,8 +198,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'redis')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='instances')
def return_if_object(module, response):

View file

@ -138,12 +138,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('projects'):
items = items.get('projects')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -153,8 +148,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'resourcemanager')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='projects')
def return_if_object(module, response):

View file

@ -98,12 +98,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('repos'):
items = items.get('repos')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -113,8 +108,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'sourcerepo')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='repos')
def return_if_object(module, response):

View file

@ -111,12 +111,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
items = fetch_list(module, collection(module))
if items.get('databases'):
items = items.get('databases')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -127,8 +122,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'spanner')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='databases')
def return_if_object(module, response):

View file

@ -114,12 +114,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
items = fetch_list(module, collection(module))
if items.get('instances'):
items = items.get('instances')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -129,8 +124,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'spanner')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='instances')
def return_if_object(module, response):

View file

@ -108,12 +108,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
items = fetch_list(module, collection(module))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -123,8 +118,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'sql')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items')
def return_if_object(module, response):

View file

@ -391,12 +391,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
items = fetch_list(module, collection(module))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -406,8 +401,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'sql')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items')
def return_if_object(module, response):

View file

@ -114,12 +114,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
items = fetch_list(module, collection(module))
if items.get('items'):
items = items.get('items')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -130,8 +125,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'sql')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='items')
def return_if_object(module, response):

View file

@ -167,12 +167,7 @@ def main():
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('nodes'):
items = items.get('nodes')
else:
items = []
return_value = {'resources': items}
return_value = {'resources': fetch_list(module, collection(module))}
module.exit_json(**return_value)
@ -182,8 +177,7 @@ def collection(module):
def fetch_list(module, link):
auth = GcpSession(module, 'tpu')
response = auth.get(link)
return return_if_object(module, response)
return auth.list(link, return_if_object, array_name='nodes')
def return_if_object(module, response):