Bug fixes for GCP modules (#54254)

pull/54262/head
The Magician 6 years ago committed by ansibot
parent 5c08afe16f
commit 65f2bfc850

@ -403,10 +403,10 @@ class SslPolicyWarningsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({u'code': item.get('code'), u'message': item.get('message')})
return remove_nones_from_dict({})
def _response_from_item(self, item):
return remove_nones_from_dict({u'code': item.get(u'code'), u'message': item.get(u'message')})
return remove_nones_from_dict({})
if __name__ == '__main__':

@ -105,10 +105,6 @@ options:
The ranges should be disjoint.
- Only IPv4 is supported.
required: false
labels:
description:
- Labels to apply to this VpnTunnel.
required: false
region:
description:
- The region where the tunnel is located.
@ -241,17 +237,6 @@ remoteTrafficSelector:
- Only IPv4 is supported.
returned: success
type: list
labels:
description:
- Labels to apply to this VpnTunnel.
returned: success
type: dict
labelFingerprint:
description:
- The fingerprint used for optimistic locking of this resource. Used internally
during updates.
returned: success
type: str
region:
description:
- The region where the tunnel is located.
@ -287,7 +272,6 @@ def main():
ike_version=dict(default=2, type='int'),
local_traffic_selector=dict(type='list', elements='str'),
remote_traffic_selector=dict(type='list', elements='str'),
labels=dict(type='dict'),
region=dict(required=True, type='str'),
)
)
@ -304,7 +288,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module), kind, fetch)
update(module, self_link(module), kind)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
@ -314,7 +298,6 @@ def main():
else:
if state == 'present':
fetch = create(module, collection(module), kind)
labels_update(module, module.params, fetch)
changed = True
else:
fetch = {}
@ -329,22 +312,8 @@ def create(module, link, kind):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))
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):
if response.get('labels') != request.get('labels'):
labels_update(module, request, response)
def labels_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/vpnTunnels/{name}/setLabels"]).format(**module.params),
{u'labels': module.params.get('labels'), u'labelFingerprint': response.get('labelFingerprint')},
)
def update(module, link, kind):
module.fail_json(msg="VpnTunnel cannot be edited")
def delete(module, link, kind):
@ -364,7 +333,6 @@ def resource_to_request(module):
u'ikeVersion': module.params.get('ike_version'),
u'localTrafficSelector': module.params.get('local_traffic_selector'),
u'remoteTrafficSelector': module.params.get('remote_traffic_selector'),
u'labels': module.params.get('labels'),
}
return_vals = {}
for k, v in request.items():
@ -441,8 +409,6 @@ def response_to_hash(module, response):
u'ikeVersion': response.get(u'ikeVersion'),
u'localTrafficSelector': response.get(u'localTrafficSelector'),
u'remoteTrafficSelector': response.get(u'remoteTrafficSelector'),
u'labels': response.get(u'labels'),
u'labelFingerprint': response.get(u'labelFingerprint'),
}

Loading…
Cancel
Save