Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Native Update Mask support
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
rambleraptor authored and modular-magician committed Jan 28, 2019
1 parent c26f617 commit d081eaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/ansible/modules/cloud/google/gcp_redis_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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'),
}


Expand Down
5 changes: 5 additions & 0 deletions lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d081eaa

Please sign in to comment.