diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy_info.py index c1fee8f98ef..80ff74e8edc 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py b/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py index d1c870c5b8f..366d50bfd36 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_pool_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_pool_info.py index ddaa80a1752..6db2ec75ead 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_pool_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_pool_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy_info.py index 1c5e02301b7..607bed65691 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy_info.py index 2058f6bd6ad..80feecb6c30 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway_info.py index 797f0f44f4b..8b94e9332b9 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_url_map_info.py b/lib/ansible/modules/cloud/google/gcp_compute_url_map_info.py index 5ab2e6d6e23..0b8bcdb2310 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_url_map_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_url_map_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel_info.py b/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel_info.py index 6ae88cdfaaf..f88cc106ca5 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py b/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py index 53823bf0293..c23957e0fce 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_container_node_pool_info.py b/lib/ansible/modules/cloud/google/gcp_container_node_pool_info.py index 1558d668fa3..7ca68117d0a 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_node_pool_info.py +++ b/lib/ansible/modules/cloud/google/gcp_container_node_pool_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_dns_managed_zone_info.py b/lib/ansible/modules/cloud/google/gcp_dns_managed_zone_info.py index a31adc65f2e..af3b3f1ccf3 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_managed_zone_info.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_managed_zone_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py index 409c18b8f81..9ce382c661d 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py @@ -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): diff --git a/lib/ansible/modules/cloud/google/gcp_iam_role_info.py b/lib/ansible/modules/cloud/google/gcp_iam_role_info.py index 85a182025ab..8c302354b28 100644 --- a/lib/ansible/modules/cloud/google/gcp_iam_role_info.py +++ b/lib/ansible/modules/cloud/google/gcp_iam_role_info.py @@ -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):