diff --git a/lib/ansible/modules/cloud/google/gcp_compute_address.py b/lib/ansible/modules/cloud/google/gcp_compute_address.py index b442082a9c5d7f..15ba8757411fd2 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_address.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_address.py @@ -258,9 +258,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -271,9 +271,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/addresses".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py index a4c822094d298b..8f98bd6894a6e9 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_bucket.py @@ -227,9 +227,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -240,9 +240,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/backendBuckets".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py index 7f46f4705317b5..257a6a46429512 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_backend_service.py @@ -703,9 +703,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -716,9 +716,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/backendServices".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_disk.py b/lib/ansible/modules/cloud/google/gcp_compute_disk.py index 5ab9da55a13934..8816ed9844fa7c 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_disk.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_disk.py @@ -523,9 +523,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -536,9 +536,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/disks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_firewall.py b/lib/ansible/modules/cloud/google/gcp_compute_firewall.py index 76ff0a3ac3d374..c128de9b4abafa 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_firewall.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_firewall.py @@ -485,9 +485,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -498,9 +498,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/firewalls".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py index bab25c7b12f4f0..94978d047422f9 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_forwarding_rule.py @@ -481,9 +481,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -494,9 +494,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/forwardingRules".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_address.py b/lib/ansible/modules/cloud/google/gcp_compute_global_address.py index 88f7adcf4b537f..dbe434f7ea4bc3 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_address.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_address.py @@ -238,9 +238,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -251,9 +251,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/addresses".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py index 8158c40a0cdd2c..05fa393d52c182 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_global_forwarding_rule.py @@ -476,9 +476,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -489,9 +489,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/forwardingRules".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_health_check.py b/lib/ansible/modules/cloud/google/gcp_compute_health_check.py index 0ac627d31f6f0f..47c3c23f1e47ab 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_health_check.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_health_check.py @@ -595,9 +595,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -608,9 +608,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/healthChecks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_http_health_check.py b/lib/ansible/modules/cloud/google/gcp_compute_http_health_check.py index fc09c76974a377..de7f5361ea4793 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_http_health_check.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_http_health_check.py @@ -289,9 +289,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -302,9 +302,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/httpHealthChecks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_https_health_check.py b/lib/ansible/modules/cloud/google/gcp_compute_https_health_check.py index a2bdfbc6fcc53f..8ee572ddd0d434 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_https_health_check.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_https_health_check.py @@ -287,9 +287,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -300,9 +300,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/httpsHealthChecks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_image.py b/lib/ansible/modules/cloud/google/gcp_compute_image.py index 13e54c2f0ab1dc..8eb3b1507ee13e 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_image.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_image.py @@ -515,9 +515,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -528,9 +528,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/images".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance.py b/lib/ansible/modules/cloud/google/gcp_compute_instance.py index 4588a55ed2a908..8978f8827a113d 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance.py @@ -969,9 +969,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -982,9 +982,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_group.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_group.py index 882c947c0b6e49..621045b2dbee52 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_group.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_group.py @@ -307,9 +307,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -320,9 +320,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py index 29555e842e1e75..abe584512ef062 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_group_manager.py @@ -407,9 +407,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -420,9 +420,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroupManagers".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance_template.py b/lib/ansible/modules/cloud/google/gcp_compute_instance_template.py index 11fc872452b8e9..42f26997c95d0a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance_template.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance_template.py @@ -932,9 +932,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -945,9 +945,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/instanceTemplates".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_network.py b/lib/ansible/modules/cloud/google/gcp_compute_network.py index e4092713f9fc0b..4ed2e2cab53b79 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_network.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_network.py @@ -250,9 +250,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -263,9 +263,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/networks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_route.py b/lib/ansible/modules/cloud/google/gcp_compute_route.py index 95db3f8c8bb6ad..b4102eb977df71 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_route.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_route.py @@ -325,9 +325,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -338,9 +338,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/routes".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_router.py b/lib/ansible/modules/cloud/google/gcp_compute_router.py index 4dde20a2991839..e1f945310f8231 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_router.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_router.py @@ -324,9 +324,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -337,9 +337,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/routers".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate.py b/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate.py index b4267dc6f3c2f4..612d20ceaa532a 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_ssl_certificate.py @@ -238,9 +238,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -251,9 +251,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/sslCertificates".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy.py b/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy.py index ebe3a01b916166..4726228965ca65 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_ssl_policy.py @@ -267,9 +267,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -280,9 +280,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/sslPolicies".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py b/lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py index 82f7c272336989..d2fe01110c72b2 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_subnetwork.py @@ -313,9 +313,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -326,9 +326,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/subnetworks".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py b/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py index a2dd5b3d6199f9..5bd7524b15b85b 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_http_proxy.py @@ -265,9 +265,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -278,9 +278,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/targetHttpProxies".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py b/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py index 926e7de3568cef..568fafa83c25c4 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_https_proxy.py @@ -365,9 +365,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -378,9 +378,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/targetHttpsProxies".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. 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 171a39485db75d..9a1c608f8e6459 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_pool.py @@ -312,9 +312,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -325,9 +325,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetPools".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py b/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py index 5edd255e37078a..a8db3628205940 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_ssl_proxy.py @@ -352,9 +352,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -365,9 +365,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/targetSslProxies".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py b/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py index 0161e24cf9311d..05f1580bfc8b5c 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_tcp_proxy.py @@ -289,9 +289,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -302,9 +302,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/targetTcpProxies".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py b/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py index c065c2cce325db..89a02ea61e8c84 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_target_vpn_gateway.py @@ -237,9 +237,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -250,9 +250,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/targetVpnGateways".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_url_map.py b/lib/ansible/modules/cloud/google/gcp_compute_url_map.py index a109044d323409..de594bf50bd66d 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_url_map.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_url_map.py @@ -426,9 +426,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -439,9 +439,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/global/urlMaps".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py b/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py index f40b50480c3871..2308285aafe0fe 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_vpn_tunnel.py @@ -370,9 +370,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'compute') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -383,9 +383,9 @@ def collection(module): return "https://www.googleapis.com/compute/v1/projects/{project}/regions/{region}/vpnTunnels".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster.py b/lib/ansible/modules/cloud/google/gcp_container_cluster.py index 3baf720f82eed2..e8fde7a8e71f3e 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster.py @@ -689,9 +689,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'container') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -702,9 +702,9 @@ def collection(module): return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters".format(**module.params) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_container_node_pool.py b/lib/ansible/modules/cloud/google/gcp_container_node_pool.py index 17ebbedc1b1919..7358b10b7bed32 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_node_pool.py +++ b/lib/ansible/modules/cloud/google/gcp_container_node_pool.py @@ -524,9 +524,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'container') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -548,9 +548,9 @@ def collection(module): return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_dns_managed_zone.py b/lib/ansible/modules/cloud/google/gcp_dns_managed_zone.py index 9d0a12981408be..df606e69196ed5 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_managed_zone.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_managed_zone.py @@ -211,9 +211,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'dns') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -224,9 +224,9 @@ def collection(module): return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py index aae7f8a263ee1a..85851f763f502f 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py @@ -238,9 +238,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'dns') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def fetch_wrapped_resource(module, kind, wrap_kind, wrap_path): @@ -277,9 +277,9 @@ def collection(module, extra_url=''): return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res) + extra_url -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py index cde8dff25d487a..50d1b735a59703 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_subscription.py @@ -241,9 +241,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'pubsub') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -254,9 +254,9 @@ def collection(module): return "https://pubsub.googleapis.com/v1/projects/{project}/subscriptions".format(**module.params) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py b/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py index 0b1b468f64335f..b715f89c4583a4 100644 --- a/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py +++ b/lib/ansible/modules/cloud/google/gcp_pubsub_topic.py @@ -150,9 +150,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'pubsub') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -163,9 +163,9 @@ def collection(module): return "https://pubsub.googleapis.com/v1/projects/{project}/topics".format(**module.params) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_database.py b/lib/ansible/modules/cloud/google/gcp_spanner_database.py index bbb37d2020f0c1..fbfb6fff70d5f7 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_database.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_database.py @@ -194,9 +194,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'spanner') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -216,9 +216,9 @@ def collection(module): return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases".format(**res) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_spanner_instance.py b/lib/ansible/modules/cloud/google/gcp_spanner_instance.py index d91a6e0103d18c..55b26f805baa53 100644 --- a/lib/ansible/modules/cloud/google/gcp_spanner_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_spanner_instance.py @@ -238,9 +238,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link): +def fetch_resource(module, link, allow_not_found=True): auth = GcpSession(module, 'spanner') - return return_if_object(module, auth.get(link)) + return return_if_object(module, auth.get(link), allow_not_found) def self_link(module): @@ -251,9 +251,9 @@ def collection(module): return "https://spanner.googleapis.com/v1/projects/{project}/instances".format(**module.params) -def return_if_object(module, response): +def return_if_object(module, response, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_sql_database.py b/lib/ansible/modules/cloud/google/gcp_sql_database.py index b8a9f3c9de9686..fd6987c93ef1d6 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_database.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_database.py @@ -204,9 +204,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'sql') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -226,7 +226,7 @@ def collection(module): return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**res) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. if response.status_code == 404: return None diff --git a/lib/ansible/modules/cloud/google/gcp_sql_instance.py b/lib/ansible/modules/cloud/google/gcp_sql_instance.py index 765df28baedd7e..2db17c7bd2daa0 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_instance.py @@ -666,9 +666,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'sql') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -679,7 +679,7 @@ def collection(module): return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. if response.status_code == 404: return None diff --git a/lib/ansible/modules/cloud/google/gcp_sql_user.py b/lib/ansible/modules/cloud/google/gcp_sql_user.py index e94b531e22fd1c..32d39fc630a563 100644 --- a/lib/ansible/modules/cloud/google/gcp_sql_user.py +++ b/lib/ansible/modules/cloud/google/gcp_sql_user.py @@ -231,9 +231,9 @@ def unwrap_resource(result, module): return None -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'sql') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def fetch_wrapped_resource(module, kind, wrap_kind, wrap_path): @@ -270,7 +270,7 @@ def collection(module): return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users".format(**res) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. if response.status_code == 404: return None diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py index 459396afe2b5f7..0014dcae63bd1b 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket.py @@ -899,9 +899,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'storage') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -912,9 +912,9 @@ def collection(module): return "https://www.googleapis.com/storage/v1/b?project={project}".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing. diff --git a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py index d6ce92cf70c3fe..cf46384356ab0a 100644 --- a/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py +++ b/lib/ansible/modules/cloud/google/gcp_storage_bucket_access_control.py @@ -267,9 +267,9 @@ def resource_to_request(module): return return_vals -def fetch_resource(module, link, kind): +def fetch_resource(module, link, kind, allow_not_found=True): auth = GcpSession(module, 'storage') - return return_if_object(module, auth.get(link), kind) + return return_if_object(module, auth.get(link), kind, allow_not_found) def self_link(module): @@ -280,9 +280,9 @@ def collection(module): return "https://www.googleapis.com/storage/v1/b/{bucket}/acl".format(**module.params) -def return_if_object(module, response, kind): +def return_if_object(module, response, kind, allow_not_found=False): # If not found, return nothing. - if response.status_code == 404: + if allow_not_found and response.status_code == 404: return None # If no content, return nothing.