Bug fixes for GCP modules (#60722)
This commit is contained in:
parent
73623c0029
commit
57a248764c
13 changed files with 29 additions and 97 deletions
|
@ -143,12 +143,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,8 +153,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -419,7 +419,11 @@ def wait_for_operation(module, response):
|
||||||
return {}
|
return {}
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
wait_done = wait_for_completion(status, op_result, module)
|
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):
|
def wait_for_completion(status, op_result, module):
|
||||||
|
|
|
@ -179,12 +179,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,8 +189,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -139,12 +139,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,8 +149,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -125,12 +125,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,8 +135,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -141,12 +141,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,8 +151,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -221,12 +221,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,8 +231,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -168,12 +168,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), query_options(module.params['filters']))
|
return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))}
|
||||||
if items.get('items'):
|
|
||||||
items = items.get('items')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,8 +178,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
response = auth.get(link, params={'filter': query})
|
return auth.list(link, return_if_object, array_name='items', params={'filter': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def query_options(filters):
|
def query_options(filters):
|
||||||
|
|
|
@ -586,12 +586,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module))
|
return_value = {'resources': fetch_list(module, collection(module))}
|
||||||
if items.get('clusters'):
|
|
||||||
items = items.get('clusters')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -601,8 +596,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link):
|
def fetch_list(module, link):
|
||||||
auth = GcpSession(module, 'container')
|
auth = GcpSession(module, 'container')
|
||||||
response = auth.get(link)
|
return auth.list(link, return_if_object, array_name='clusters')
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def return_if_object(module, response):
|
def return_if_object(module, response):
|
||||||
|
|
|
@ -371,12 +371,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module))
|
return_value = {'resources': fetch_list(module, collection(module))}
|
||||||
if items.get('nodePools'):
|
|
||||||
items = items.get('nodePools')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -387,8 +382,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link):
|
def fetch_list(module, link):
|
||||||
auth = GcpSession(module, 'container')
|
auth = GcpSession(module, 'container')
|
||||||
response = auth.get(link)
|
return auth.list(link, return_if_object, array_name='nodePools')
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def return_if_object(module, response):
|
def return_if_object(module, response):
|
||||||
|
|
|
@ -214,12 +214,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module), module.params['dns_name'])
|
return_value = {'resources': fetch_list(module, collection(module), module.params['dns_name'])}
|
||||||
if items.get('managedZones'):
|
|
||||||
items = items.get('managedZones')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,8 +224,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link, query):
|
def fetch_list(module, link, query):
|
||||||
auth = GcpSession(module, 'dns')
|
auth = GcpSession(module, 'dns')
|
||||||
response = auth.get(link, params={'dnsName': query})
|
return auth.list(link, return_if_object, array_name='managedZones', params={'dnsName': query})
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def return_if_object(module, response):
|
def return_if_object(module, response):
|
||||||
|
|
|
@ -117,12 +117,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module))
|
return_value = {'resources': fetch_list(module, collection(module))}
|
||||||
if items.get('rrsets'):
|
|
||||||
items = items.get('rrsets')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,8 +128,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link):
|
def fetch_list(module, link):
|
||||||
auth = GcpSession(module, 'dns')
|
auth = GcpSession(module, 'dns')
|
||||||
response = auth.get(link)
|
return auth.list(link, return_if_object, array_name='rrsets')
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def return_if_object(module, response):
|
def return_if_object(module, response):
|
||||||
|
|
|
@ -112,12 +112,7 @@ def main():
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/iam']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/iam']
|
||||||
|
|
||||||
items = fetch_list(module, collection(module))
|
return_value = {'resources': fetch_list(module, collection(module))}
|
||||||
if items.get('roles'):
|
|
||||||
items = items.get('roles')
|
|
||||||
else:
|
|
||||||
items = []
|
|
||||||
return_value = {'resources': items}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,8 +122,7 @@ def collection(module):
|
||||||
|
|
||||||
def fetch_list(module, link):
|
def fetch_list(module, link):
|
||||||
auth = GcpSession(module, 'iam')
|
auth = GcpSession(module, 'iam')
|
||||||
response = auth.get(link)
|
return auth.list(link, return_if_object, array_name='roles')
|
||||||
return return_if_object(module, response)
|
|
||||||
|
|
||||||
|
|
||||||
def return_if_object(module, response):
|
def return_if_object(module, response):
|
||||||
|
|
Loading…
Reference in a new issue