From 6be624884cd0c0e887cb3259fb2b8b14c24d52e4 Mon Sep 17 00:00:00 2001 From: megan07 Date: Fri, 16 Aug 2019 21:48:37 +0000 Subject: [PATCH] Add bigtable app profile resource Signed-off-by: Modular Magician --- lib/ansible/module_utils/gcp_utils.py | 24 ------------------- .../gcp_appengine_firewall_rule_info.py | 10 ++++++-- .../cloud/google/gcp_bigquery_dataset_info.py | 10 ++++++-- .../cloud/google/gcp_bigquery_table_info.py | 10 ++++++-- .../google/gcp_cloudbuild_trigger_info.py | 10 ++++++-- .../gcp_cloudfunctions_cloud_function_info.py | 10 ++++++-- .../google/gcp_cloudscheduler_job_info.py | 10 ++++++-- .../cloud/google/gcp_cloudtasks_queue_info.py | 10 ++++++-- .../cloud/google/gcp_compute_address_info.py | 10 ++++++-- .../google/gcp_compute_autoscaler_info.py | 10 ++++++-- .../google/gcp_compute_backend_bucket_info.py | 10 ++++++-- .../gcp_compute_backend_service_info.py | 10 ++++++-- .../cloud/google/gcp_compute_disk_info.py | 10 ++++++-- .../cloud/google/gcp_compute_firewall_info.py | 10 ++++++-- .../gcp_compute_forwarding_rule_info.py | 10 ++++++-- .../google/gcp_compute_global_address_info.py | 10 ++++++-- ...gcp_compute_global_forwarding_rule_info.py | 10 ++++++-- .../google/gcp_compute_health_check_info.py | 10 ++++++-- .../gcp_compute_http_health_check_info.py | 10 ++++++-- .../gcp_compute_https_health_check_info.py | 10 ++++++-- .../cloud/google/gcp_compute_image_info.py | 10 ++++++-- .../google/gcp_compute_instance_group_info.py | 10 ++++++-- ...gcp_compute_instance_group_manager_info.py | 10 ++++++-- .../cloud/google/gcp_compute_instance_info.py | 10 ++++++-- .../gcp_compute_instance_template_info.py | 10 ++++++-- ...cp_compute_interconnect_attachment_info.py | 10 ++++++-- .../cloud/google/gcp_compute_network_info.py | 10 ++++++-- .../google/gcp_compute_region_disk_info.py | 10 ++++++-- .../cloud/google/gcp_compute_route_info.py | 10 ++++++-- .../cloud/google/gcp_compute_router_info.py | 10 ++++++-- .../cloud/google/gcp_compute_snapshot_info.py | 10 ++++++-- .../gcp_compute_ssl_certificate_info.py | 10 ++++++-- .../google/gcp_compute_ssl_policy_info.py | 10 ++++++-- .../google/gcp_compute_subnetwork_info.py | 10 ++++++-- .../gcp_compute_target_http_proxy_info.py | 10 ++++++-- .../gcp_compute_target_https_proxy_info.py | 10 ++++++-- .../google/gcp_compute_target_pool_info.py | 10 ++++++-- .../gcp_compute_target_ssl_proxy_info.py | 10 ++++++-- .../gcp_compute_target_tcp_proxy_info.py | 10 ++++++-- .../gcp_compute_target_vpn_gateway_info.py | 10 ++++++-- .../cloud/google/gcp_compute_url_map_info.py | 10 ++++++-- .../google/gcp_compute_vpn_tunnel_info.py | 10 ++++++-- .../google/gcp_container_cluster_info.py | 10 ++++++-- .../google/gcp_container_node_pool_info.py | 10 ++++++-- .../cloud/google/gcp_dns_managed_zone_info.py | 10 ++++++-- .../gcp_dns_resource_record_set_info.py | 10 ++++++-- .../modules/cloud/google/gcp_iam_role_info.py | 10 ++++++-- .../google/gcp_iam_service_account_info.py | 10 ++++++-- .../cloud/google/gcp_mlengine_model_info.py | 10 ++++++-- .../cloud/google/gcp_mlengine_version_info.py | 10 ++++++-- .../google/gcp_pubsub_subscription_info.py | 10 ++++++-- .../cloud/google/gcp_pubsub_topic_info.py | 10 ++++++-- .../cloud/google/gcp_redis_instance_info.py | 10 ++++++-- .../gcp_resourcemanager_project_info.py | 10 ++++++-- .../google/gcp_sourcerepo_repository_info.py | 10 ++++++-- .../cloud/google/gcp_spanner_database_info.py | 10 ++++++-- .../cloud/google/gcp_spanner_instance_info.py | 10 ++++++-- .../cloud/google/gcp_sql_database_info.py | 10 ++++++-- .../cloud/google/gcp_sql_instance_info.py | 10 ++++++-- .../modules/cloud/google/gcp_sql_user_info.py | 10 ++++++-- .../modules/cloud/google/gcp_tpu_node_info.py | 10 ++++++-- 61 files changed, 480 insertions(+), 144 deletions(-) diff --git a/lib/ansible/module_utils/gcp_utils.py b/lib/ansible/module_utils/gcp_utils.py index 44cca3909a162d..dd4ef0104df242 100644 --- a/lib/ansible/module_utils/gcp_utils.py +++ b/lib/ansible/module_utils/gcp_utils.py @@ -119,30 +119,6 @@ def patch(self, url, body=None, **kwargs): 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')) diff --git a/lib/ansible/modules/cloud/google/gcp_appengine_firewall_rule_info.py b/lib/ansible/modules/cloud/google/gcp_appengine_firewall_rule_info.py index e2b6317a4449a8..b24673b3df585d 100644 --- a/lib/ansible/modules/cloud/google/gcp_appengine_firewall_rule_info.py +++ b/lib/ansible/modules/cloud/google/gcp_appengine_firewall_rule_info.py @@ -101,7 +101,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('ingressRules'): + items = items.get('ingressRules') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -111,7 +116,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'appengine') - return auth.list(link, return_if_object, array_name='ingressRules') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py index 3cc270f6a98ddd..9af87b929f1a1a 100644 --- a/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py +++ b/lib/ansible/modules/cloud/google/gcp_bigquery_dataset_info.py @@ -208,7 +208,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/bigquery'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('datasets'): + items = items.get('datasets') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -218,7 +223,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'bigquery') - return auth.list(link, return_if_object, array_name='datasets') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_bigquery_table_info.py b/lib/ansible/modules/cloud/google/gcp_bigquery_table_info.py index 1491deeabcdcf5..8ed6377925cdb6 100644 --- a/lib/ansible/modules/cloud/google/gcp_bigquery_table_info.py +++ b/lib/ansible/modules/cloud/google/gcp_bigquery_table_info.py @@ -546,7 +546,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/bigquery'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('tables'): + items = items.get('tables') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -556,7 +561,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'bigquery') - return auth.list(link, return_if_object, array_name='tables') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_info.py b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_info.py index ec581c6f3e7dcc..dabacbdd231634 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_info.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudbuild_trigger_info.py @@ -324,7 +324,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('triggers'): + items = items.get('triggers') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -334,7 +339,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'cloudbuild') - return auth.list(link, return_if_object, array_name='triggers') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_cloudfunctions_cloud_function_info.py b/lib/ansible/modules/cloud/google/gcp_cloudfunctions_cloud_function_info.py index 34aa2c1b4a3c28..8cfc95227539d4 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudfunctions_cloud_function_info.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudfunctions_cloud_function_info.py @@ -224,7 +224,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('functions'): + items = items.get('functions') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -234,7 +239,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'cloudfunctions') - return auth.list(link, return_if_object, array_name='functions') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_cloudscheduler_job_info.py b/lib/ansible/modules/cloud/google/gcp_cloudscheduler_job_info.py index 7aee6c8d6d3a85..831575188dccfc 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudscheduler_job_info.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudscheduler_job_info.py @@ -311,7 +311,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('jobs'): + items = items.get('jobs') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -321,7 +326,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'cloudscheduler') - return auth.list(link, return_if_object, array_name='jobs') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_cloudtasks_queue_info.py b/lib/ansible/modules/cloud/google/gcp_cloudtasks_queue_info.py index 0598c87927d3de..b84e6a676301b3 100644 --- a/lib/ansible/modules/cloud/google/gcp_cloudtasks_queue_info.py +++ b/lib/ansible/modules/cloud/google/gcp_cloudtasks_queue_info.py @@ -216,7 +216,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('queues'): + items = items.get('queues') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -226,7 +231,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'cloudtasks') - return auth.list(link, return_if_object, array_name='queues') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_address_info.py b/lib/ansible/modules/cloud/google/gcp_compute_address_info.py index a7791eaa36d224..93e3ee89df76c9 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_address_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_address_info.py @@ -159,7 +159,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -169,7 +174,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_autoscaler_info.py b/lib/ansible/modules/cloud/google/gcp_compute_autoscaler_info.py index 8c957f8b09fbfa..18481849b9a048 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_autoscaler_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_autoscaler_info.py @@ -224,7 +224,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -234,7 +239,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_info.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_info.py index 2d6c62a265ea8b..c7d214b8ec42ff 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket_info.py @@ -142,7 +142,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -152,7 +157,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_info.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_info.py index 5d529126bf53ce..f1535151c84d23 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service_info.py @@ -379,7 +379,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -389,7 +394,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_disk_info.py b/lib/ansible/modules/cloud/google/gcp_compute_disk_info.py index 7e15d9480b1279..0c4451f9ec37d5 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_disk_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_disk_info.py @@ -302,7 +302,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -312,7 +317,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_firewall_info.py b/lib/ansible/modules/cloud/google/gcp_compute_firewall_info.py index 1013fa4144d8d9..2349358eb13dc8 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_firewall_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_firewall_info.py @@ -258,7 +258,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -268,7 +273,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_info.py b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_info.py index c4b9763fa3cdfd..0ce70ff07082a5 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule_info.py @@ -260,7 +260,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -270,7 +275,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_address_info.py b/lib/ansible/modules/cloud/google/gcp_compute_global_address_info.py index e6a115a2f53a1d..0dfd07d5336418 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_address_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_address_info.py @@ -159,7 +159,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -169,7 +174,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_info.py b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_info.py index c10fc014b34731..de5b4cd42b4601 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule_info.py @@ -189,7 +189,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -199,7 +204,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_health_check_info.py b/lib/ansible/modules/cloud/google/gcp_compute_health_check_info.py index 3e54f6740f17d6..d2bae2ca266c82 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_health_check_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_health_check_info.py @@ -369,7 +369,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -379,7 +384,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_http_health_check_info.py b/lib/ansible/modules/cloud/google/gcp_compute_http_health_check_info.py index 528460553d61d3..62bb56f31447dc 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_http_health_check_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_http_health_check_info.py @@ -159,7 +159,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -169,7 +174,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_https_health_check_info.py b/lib/ansible/modules/cloud/google/gcp_compute_https_health_check_info.py index 868b051ff2acf7..7101935677510a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_https_health_check_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_https_health_check_info.py @@ -159,7 +159,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -169,7 +174,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_image_info.py b/lib/ansible/modules/cloud/google/gcp_compute_image_info.py index 6d8c14b652fa0e..b7a128e52076d9 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_image_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_image_info.py @@ -301,7 +301,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -311,7 +316,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_info.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_info.py index 59d27856cd02a2..493a57922832c3 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_info.py @@ -168,7 +168,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -178,7 +183,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager_info.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager_info.py index aa872bd0bfaf88..ef7b9d45ccf9cc 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager_info.py @@ -243,7 +243,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -253,7 +258,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_info.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_info.py index 988e67cd50df6b..fc4ee5a32dccc5 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_info.py @@ -530,7 +530,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -540,7 +545,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_template_info.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_template_info.py index 5974e9ca405a78..1db5b2962faba1 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_template_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_template_info.py @@ -488,7 +488,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -498,7 +503,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment_info.py b/lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment_info.py index 8ccb8aa919ffed..12be2a87030f33 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_interconnect_attachment_info.py @@ -225,7 +225,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -235,7 +240,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_network_info.py b/lib/ansible/modules/cloud/google/gcp_compute_network_info.py index 4ea9cc1a217f35..aea0a3876527b3 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_network_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_network_info.py @@ -162,7 +162,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -172,7 +177,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_region_disk_info.py b/lib/ansible/modules/cloud/google/gcp_compute_region_disk_info.py index 008162bb03d4bc..9f14ae66346c5d 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_region_disk_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_region_disk_info.py @@ -248,7 +248,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -258,7 +263,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_route_info.py b/lib/ansible/modules/cloud/google/gcp_compute_route_info.py index a3c05e6e299894..cbe4caf4e52406 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_route_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_route_info.py @@ -162,7 +162,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -172,7 +177,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_router_info.py b/lib/ansible/modules/cloud/google/gcp_compute_router_info.py index f3a9f8248f5923..d24bf62c63fccd 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_router_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_router_info.py @@ -178,7 +178,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -188,7 +193,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_snapshot_info.py b/lib/ansible/modules/cloud/google/gcp_compute_snapshot_info.py index 3ee3336d153baa..de4e0dc9da2cb1 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_snapshot_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_snapshot_info.py @@ -191,7 +191,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -201,7 +206,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate_info.py b/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate_info.py index c97bad2e82c907..bf782b5e8bda6b 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate_info.py @@ -126,7 +126,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -136,7 +141,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy_info.py b/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy_info.py index dcc1cf300f02a3..7509097455292b 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy_info.py @@ -164,7 +164,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -174,7 +179,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_subnetwork_info.py b/lib/ansible/modules/cloud/google/gcp_compute_subnetwork_info.py index f167cab80c2ef5..7d3419bfd34d8a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_subnetwork_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_subnetwork_info.py @@ -187,7 +187,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -197,7 +202,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy_info.py b/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy_info.py index 5e0b89d2f83031..0188497d73f5b1 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy_info.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy_info.py @@ -120,7 +120,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -130,7 +135,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): 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 80ff74e8edc7d6..c1fee8f98eff1c 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,7 +143,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -153,7 +158,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) def query_options(filters): 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 6db2ec75eada73..ddaa80a17524d3 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,7 +179,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -189,7 +194,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 607bed656917ce..1c5e02301b768f 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,7 +139,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -149,7 +154,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 80feecb6c30aff..2058f6bd6ad741 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,7 +125,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -135,7 +140,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 8b94e9332b9e11..797f0f44f4b79a 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,7 +141,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -151,7 +156,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 0b8bcdb2310abe..5ab2e6d6e238a2 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,7 +221,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -231,7 +236,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 f88cc106ca519d..6ae88cdfaaf9b8 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,7 +168,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/compute'] - return_value = {'resources': fetch_list(module, collection(module), query_options(module.params['filters']))} + 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} module.exit_json(**return_value) @@ -178,7 +183,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'compute') - return auth.list(link, return_if_object, array_name='items', params={'filter': query}) + response = auth.get(link, params={'filter': query}) + return return_if_object(module, response) 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 c23957e0fced20..53823bf0293fe8 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py @@ -586,7 +586,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('clusters'): + items = items.get('clusters') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -596,7 +601,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'container') - return auth.list(link, return_if_object, array_name='clusters') + response = auth.get(link) + return return_if_object(module, response) 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 7ca68117d0ad2e..1558d668fa3229 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,7 +371,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('nodePools'): + items = items.get('nodePools') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -382,7 +387,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'container') - return auth.list(link, return_if_object, array_name='nodePools') + response = auth.get(link) + return return_if_object(module, response) 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 af3b3f1ccf3269..a31adc65f2e74a 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,7 +214,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite'] - return_value = {'resources': fetch_list(module, collection(module), module.params['dns_name'])} + items = 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) @@ -224,7 +229,8 @@ def collection(module): def fetch_list(module, link, query): auth = GcpSession(module, 'dns') - return auth.list(link, return_if_object, array_name='managedZones', params={'dnsName': query}) + response = auth.get(link, params={'dnsName': query}) + return return_if_object(module, response) 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 9ce382c661d924..409c18b8f81127 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,7 +117,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('rrsets'): + items = items.get('rrsets') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -128,7 +133,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'dns') - return auth.list(link, return_if_object, array_name='rrsets') + response = auth.get(link) + return return_if_object(module, response) 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 8c302354b28b73..85a182025ab77a 100644 --- a/lib/ansible/modules/cloud/google/gcp_iam_role_info.py +++ b/lib/ansible/modules/cloud/google/gcp_iam_role_info.py @@ -112,7 +112,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/iam'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('roles'): + items = items.get('roles') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -122,7 +127,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'iam') - return auth.list(link, return_if_object, array_name='roles') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py b/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py index f3f56495a6c1a0..2f22bde5449e39 100644 --- a/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py +++ b/lib/ansible/modules/cloud/google/gcp_iam_service_account_info.py @@ -111,7 +111,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/iam'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('accounts'): + items = items.get('accounts') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -121,7 +126,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'iam') - return auth.list(link, return_if_object, array_name='accounts') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py b/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py index 0dfdcf24865d15..4605c08057f913 100644 --- a/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py +++ b/lib/ansible/modules/cloud/google/gcp_mlengine_model_info.py @@ -120,7 +120,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('models'): + items = items.get('models') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -130,7 +135,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'mlengine') - return auth.list(link, return_if_object, array_name='models') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py b/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py index 86eb8780867a95..de02cb2508ddd5 100644 --- a/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py +++ b/lib/ansible/modules/cloud/google/gcp_mlengine_version_info.py @@ -211,7 +211,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('versions'): + items = items.get('versions') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -222,7 +227,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'mlengine') - return auth.list(link, return_if_object, array_name='versions') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py index 7748f9369914fa..a0d4c487851f83 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription_info.py @@ -190,7 +190,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('subscriptions'): + items = items.get('subscriptions') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -200,7 +205,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'pubsub') - return auth.list(link, return_if_object, array_name='subscriptions') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py b/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py index 648070db953794..66923471de31f5 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_topic_info.py @@ -117,7 +117,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('topics'): + items = items.get('topics') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -127,7 +132,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'pubsub') - return auth.list(link, return_if_object, array_name='topics') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py b/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py index 72fdca38f325e8..213b0c711670c5 100644 --- a/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_redis_instance_info.py @@ -188,7 +188,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('instances'): + items = items.get('instances') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -198,7 +203,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'redis') - return auth.list(link, return_if_object, array_name='instances') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py b/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py index 64cf786b961b77..1f5fd17d751edb 100644 --- a/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py +++ b/lib/ansible/modules/cloud/google/gcp_resourcemanager_project_info.py @@ -138,7 +138,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('projects'): + items = items.get('projects') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -148,7 +153,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'resourcemanager') - return auth.list(link, return_if_object, array_name='projects') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py index 2e9cef2531cd8f..baecdd483f2926 100644 --- a/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sourcerepo_repository_info.py @@ -98,7 +98,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('repos'): + items = items.get('repos') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -108,7 +113,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sourcerepo') - return auth.list(link, return_if_object, array_name='repos') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py b/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py index 8f35a88b8f3edc..24c6d322e0a2bc 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database_info.py @@ -111,7 +111,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('databases'): + items = items.get('databases') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -122,7 +127,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'spanner') - return auth.list(link, return_if_object, array_name='databases') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py b/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py index 5f286b85ff5874..375ea6d20e0cef 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_instance_info.py @@ -114,7 +114,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('instances'): + items = items.get('instances') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -124,7 +129,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'spanner') - return auth.list(link, return_if_object, array_name='instances') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database_info.py b/lib/ansible/modules/cloud/google/gcp_sql_database_info.py index c60f1e3136310d..6d1b34654bb510 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database_info.py @@ -108,7 +108,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('items'): + items = items.get('items') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -118,7 +123,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sql') - return auth.list(link, return_if_object, array_name='items') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sql_instance_info.py b/lib/ansible/modules/cloud/google/gcp_sql_instance_info.py index ac3a4d700e3f1f..11bec27a6d38a4 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_instance_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_instance_info.py @@ -391,7 +391,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('items'): + items = items.get('items') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -401,7 +406,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sql') - return auth.list(link, return_if_object, array_name='items') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user_info.py b/lib/ansible/modules/cloud/google/gcp_sql_user_info.py index 8e69002da267c3..36e9204c1c7d32 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user_info.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user_info.py @@ -114,7 +114,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('items'): + items = items.get('items') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -125,7 +130,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'sql') - return auth.list(link, return_if_object, array_name='items') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response): diff --git a/lib/ansible/modules/cloud/google/gcp_tpu_node_info.py b/lib/ansible/modules/cloud/google/gcp_tpu_node_info.py index a509a62513acca..57e63b495ccaac 100644 --- a/lib/ansible/modules/cloud/google/gcp_tpu_node_info.py +++ b/lib/ansible/modules/cloud/google/gcp_tpu_node_info.py @@ -167,7 +167,12 @@ def main(): if not module.params['scopes']: module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform'] - return_value = {'resources': fetch_list(module, collection(module))} + items = fetch_list(module, collection(module)) + if items.get('nodes'): + items = items.get('nodes') + else: + items = [] + return_value = {'resources': items} module.exit_json(**return_value) @@ -177,7 +182,8 @@ def collection(module): def fetch_list(module, link): auth = GcpSession(module, 'tpu') - return auth.list(link, return_if_object, array_name='nodes') + response = auth.get(link) + return return_if_object(module, response) def return_if_object(module, response):