Bug fixes for GCP modules (#60722)

This commit is contained in:
The Magician 2019-08-19 12:52:58 -07:00 committed by ansibot
parent 73623c0029
commit 57a248764c
13 changed files with 29 additions and 97 deletions

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

@ -419,7 +419,11 @@ def wait_for_operation(module, response):
return {}
status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module)
return decode_response(fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetPool'), module)
response = fetch_resource(module, navigate_hash(wait_done, ['targetLink']), 'compute#targetPool')
if response:
return decode_response(response, module)
else:
return {}
def wait_for_completion(status, op_result, module):

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):