From d081eaa700671d6a97eb38f239c402671f1f5d85 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Mon, 28 Jan 2019 22:44:20 +0000 Subject: [PATCH] Native Update Mask support Signed-off-by: Modular Magician --- .../cloud/google/gcp_redis_instance.py | 29 +++++++++++++++++-- .../cloud/google/gcp_redis_instance_facts.py | 5 ++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_redis_instance.py b/lib/ansible/modules/cloud/google/gcp_redis_instance.py index c096b0ba1a85fa..ccb98a8116dc53 100644 --- a/lib/ansible/modules/cloud/google/gcp_redis_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_redis_instance.py @@ -244,6 +244,11 @@ instance - STANDARD_HA: highly available primary/replica instances .' returned: success type: str +updateMask: + description: + - The update mask (internal only). + returned: success + type: str region: description: - The name of the Redis region of the instance. @@ -296,7 +301,7 @@ def main(): if fetch: if state == 'present': if is_different(module, fetch): - update(module, self_link(module)) + update(module, self_link(module), fetch) fetch = fetch_resource(module, self_link(module)) changed = True else: @@ -320,8 +325,25 @@ def create(module, link): return wait_for_operation(module, auth.post(link, resource_to_request(module))) -def update(module, link): - module.fail_json(msg="Instance cannot be edited") +def update(module, link, fetch): + auth = GcpSession(module, 'redis') + params = {'updateMask': updateMask(resource_to_request(module), response_to_hash(module, fetch))} + request = resource_to_request(module) + del request['name'] + return wait_for_operation(module, auth.patch(link, request, params=params)) + + +def updateMask(request, response): + update_mask = [] + if request.get('displayName') != response.get('displayName'): + update_mask.append('displayName') + if request.get('labels') != response.get('labels'): + update_mask.append('labels') + if request.get('redisConfigs') != response.get('redisConfigs'): + update_mask.append('redisConfigs') + if request.get('memorySizeGb') != response.get('memorySizeGb'): + update_mask.append('memorySizeGb') + return ','.join(update_mask) def delete(module, link): @@ -422,6 +444,7 @@ def response_to_hash(module, response): u'redisVersion': module.params.get('redis_version'), u'reservedIpRange': module.params.get('reserved_ip_range'), u'tier': module.params.get('tier'), + u'updateMask': response.get(u'updateMask'), } diff --git a/lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py b/lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py index 6a00cf4a3f601c..c595e653960288 100644 --- a/lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py +++ b/lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py @@ -158,6 +158,11 @@ instance - STANDARD_HA: highly available primary/replica instances .' returned: success type: str + updateMask: + description: + - The update mask (internal only). + returned: success + type: str region: description: - The name of the Redis region of the instance.