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 c1fee8f98e..80ff74e8ed 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 d1c870c5b8..366d50bfd3 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 ddaa80a175..6db2ec75ea 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 1c5e02301b..607bed6569 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 2058f6bd6a..80feecb6c3 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 797f0f44f4..8b94e9332b 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 5ab2e6d6e2..0b8bcdb231 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 6ae88cdfaa..f88cc106ca 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 53823bf029..c23957e0fc 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 1558d668fa..7ca68117d0 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 a31adc65f2..af3b3f1ccf 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 409c18b8f8..9ce382c661 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 85a182025a..8c302354b2 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):