mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-07-26 06:31:32 -07:00
GCP MagicModules bug fixes (#47285)
Closes: #46930 #46929 #46928 #46927 #46926 #46925 #46924 #46923 #46922 #46921 #46920 #46919 #46918 #46917 #46916 #46915 #46914 #46913 #46912 #46911 #46910 #46909 #46908 #46907 #46906 #46905 #46903 #46902 #46901 #46900 #46899 #46898 #46897 #46896 #46895 #46894 #46893 #46892 #46891 #46890 #46889 #46888 #46887 #46886 #46885 #46884 #46883 #46882 #46881 #46880 #46879 #46878 #46877 #46876 #46875 #46874 #46873 #46872 #46871 #46870 #46869 #46868 #46867 #46866 #46865 #46864 #46863 #46862 #46861 #46860 #46859 #46858 #46857 #46856 #46855 #46854 #46853 #46852
This commit is contained in:
parent
84f0e2c5b2
commit
5c97cc1da0
78 changed files with 2531 additions and 1137 deletions
|
@ -67,6 +67,15 @@ options:
|
|||
The default value is IPV4.
|
||||
required: false
|
||||
choices: ['IPV4', 'IPV6']
|
||||
address_type:
|
||||
description:
|
||||
- The type of the address to reserve, default is EXTERNAL.
|
||||
- "* EXTERNAL indicates public/external single IP address."
|
||||
- "* INTERNAL indicates internal IP ranges belonging to some network."
|
||||
required: false
|
||||
default: EXTERNAL
|
||||
version_added: 2.8
|
||||
choices: ['EXTERNAL', 'INTERNAL']
|
||||
extends_documentation_fragment: gcp
|
||||
notes:
|
||||
- "API Reference: U(https://cloud.google.com/compute/docs/reference/latest/globalAddresses)"
|
||||
|
@ -78,7 +87,7 @@ EXAMPLES = '''
|
|||
gcp_compute_global_address:
|
||||
name: "test_object"
|
||||
project: "test_project"
|
||||
auth_kind: "service_account"
|
||||
auth_kind: "serviceaccount"
|
||||
service_account_file: "/tmp/auth.pem"
|
||||
state: present
|
||||
'''
|
||||
|
@ -89,7 +98,7 @@ RETURN = '''
|
|||
- The static external IP address represented by this resource.
|
||||
returned: success
|
||||
type: str
|
||||
creation_timestamp:
|
||||
creationTimestamp:
|
||||
description:
|
||||
- Creation timestamp in RFC3339 text format.
|
||||
returned: success
|
||||
|
@ -115,7 +124,13 @@ RETURN = '''
|
|||
be a dash.
|
||||
returned: success
|
||||
type: str
|
||||
ip_version:
|
||||
labelFingerprint:
|
||||
description:
|
||||
- The fingerprint used for optimistic locking of this resource. Used internally during
|
||||
updates.
|
||||
returned: success
|
||||
type: str
|
||||
ipVersion:
|
||||
description:
|
||||
- The IP Version that will be used by this address. Valid options are IPV4 or IPV6.
|
||||
The default value is IPV4.
|
||||
|
@ -126,6 +141,13 @@ RETURN = '''
|
|||
- A reference to the region where the regional address resides.
|
||||
returned: success
|
||||
type: str
|
||||
addressType:
|
||||
description:
|
||||
- The type of the address to reserve, default is EXTERNAL.
|
||||
- "* EXTERNAL indicates public/external single IP address."
|
||||
- "* INTERNAL indicates internal IP ranges belonging to some network."
|
||||
returned: success
|
||||
type: str
|
||||
'''
|
||||
|
||||
################################################################################
|
||||
|
@ -150,7 +172,8 @@ def main():
|
|||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||
description=dict(type='str'),
|
||||
name=dict(required=True, type='str'),
|
||||
ip_version=dict(type='str', choices=['IPV4', 'IPV6'])
|
||||
ip_version=dict(type='str', choices=['IPV4', 'IPV6']),
|
||||
address_type=dict(default='EXTERNAL', type='str', choices=['EXTERNAL', 'INTERNAL'])
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -166,7 +189,8 @@ def main():
|
|||
if fetch:
|
||||
if state == 'present':
|
||||
if is_different(module, fetch):
|
||||
fetch = update(module, self_link(module), kind)
|
||||
update(module, self_link(module), kind, fetch)
|
||||
fetch = fetch_resource(module, self_link(module), kind)
|
||||
changed = True
|
||||
else:
|
||||
delete(module, self_link(module), kind)
|
||||
|
@ -189,9 +213,27 @@ def create(module, link, kind):
|
|||
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
|
||||
|
||||
|
||||
def update(module, link, kind):
|
||||
def update(module, link, kind, fetch):
|
||||
update_fields(module, resource_to_request(module),
|
||||
response_to_hash(module, fetch))
|
||||
return fetch_resource(module, self_link(module), kind)
|
||||
|
||||
|
||||
def update_fields(module, request, response):
|
||||
pass
|
||||
|
||||
|
||||
def label_fingerprint_update(module, request, response):
|
||||
auth = GcpSession(module, 'compute')
|
||||
return wait_for_operation(module, auth.put(link, resource_to_request(module)))
|
||||
auth.post(
|
||||
''.join([
|
||||
"https://www.googleapis.com/compute/v1/",
|
||||
"projects/{project}/global/addresses/{name}/setLabels"
|
||||
]).format(**module.params),
|
||||
{
|
||||
u'labelFingerprint': response.get('labelFingerprint')
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def delete(module, link, kind):
|
||||
|
@ -204,7 +246,8 @@ def resource_to_request(module):
|
|||
u'kind': 'compute#address',
|
||||
u'description': module.params.get('description'),
|
||||
u'name': module.params.get('name'),
|
||||
u'ipVersion': module.params.get('ip_version')
|
||||
u'ipVersion': module.params.get('ip_version'),
|
||||
u'addressType': module.params.get('address_type')
|
||||
}
|
||||
return_vals = {}
|
||||
for k, v in request.items():
|
||||
|
@ -214,9 +257,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):
|
||||
|
@ -227,9 +270,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.
|
||||
|
@ -244,8 +287,6 @@ def return_if_object(module, response, kind):
|
|||
|
||||
if navigate_hash(result, ['error', 'errors']):
|
||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||
if result['kind'] != kind:
|
||||
module.fail_json(msg="Incorrect result: {kind}".format(**result))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -277,8 +318,10 @@ def response_to_hash(module, response):
|
|||
u'description': response.get(u'description'),
|
||||
u'id': response.get(u'id'),
|
||||
u'name': response.get(u'name'),
|
||||
u'labelFingerprint': response.get(u'labelFingerprint'),
|
||||
u'ipVersion': response.get(u'ipVersion'),
|
||||
u'region': response.get(u'region')
|
||||
u'region': response.get(u'region'),
|
||||
u'addressType': response.get(u'addressType')
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue