Bug fixes for GCP modules (#60340)

This commit is contained in:
The Magician 2019-08-09 16:17:36 -07:00 committed by ansibot
parent 1b45abc4f3
commit 5d4c3ad97e
4 changed files with 86 additions and 11 deletions

View file

@ -68,6 +68,24 @@ options:
required: false required: false
type: dict type: dict
version_added: 2.8 version_added: 2.8
message_storage_policy:
description:
- Policy constraining the set of Google Cloud Platform regions where messages
published to the topic may be stored. If not present, then no constraints are
in effect.
required: false
type: dict
version_added: 2.9
suboptions:
allowed_persistence_regions:
description:
- A list of IDs of GCP regions where messages that are published to the topic
may be persisted in storage. Messages published by publishers running in
non-allowed GCP regions (or running outside of GCP altogether) will be routed
for storage in one of the allowed regions. An empty list means that no regions
are allowed, and is not a valid configuration.
required: true
type: list
extends_documentation_fragment: gcp extends_documentation_fragment: gcp
notes: notes:
- 'API Reference: U(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)' - 'API Reference: U(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics)'
@ -103,13 +121,29 @@ labels:
- A set of key/value label pairs to assign to this Topic. - A set of key/value label pairs to assign to this Topic.
returned: success returned: success
type: dict type: dict
messageStoragePolicy:
description:
- Policy constraining the set of Google Cloud Platform regions where messages published
to the topic may be stored. If not present, then no constraints are in effect.
returned: success
type: complex
contains:
allowedPersistenceRegions:
description:
- A list of IDs of GCP regions where messages that are published to the topic
may be persisted in storage. Messages published by publishers running in non-allowed
GCP regions (or running outside of GCP altogether) will be routed for storage
in one of the allowed regions. An empty list means that no regions are allowed,
and is not a valid configuration.
returned: success
type: list
''' '''
################################################################################ ################################################################################
# Imports # Imports
################################################################################ ################################################################################
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, remove_nones_from_dict, replace_resource_dict
import json import json
import re import re
@ -127,6 +161,7 @@ def main():
name=dict(required=True, type='str'), name=dict(required=True, type='str'),
kms_key_name=dict(type='str'), kms_key_name=dict(type='str'),
labels=dict(type='dict'), labels=dict(type='dict'),
message_storage_policy=dict(type='dict', options=dict(allowed_persistence_regions=dict(required=True, type='list', elements='str'))),
) )
) )
@ -177,6 +212,8 @@ def updateMask(request, response):
update_mask = [] update_mask = []
if request.get('labels') != response.get('labels'): if request.get('labels') != response.get('labels'):
update_mask.append('labels') update_mask.append('labels')
if request.get('messageStoragePolicy') != response.get('messageStoragePolicy'):
update_mask.append('messageStoragePolicy')
return ','.join(update_mask) return ','.join(update_mask)
@ -190,6 +227,7 @@ def resource_to_request(module):
u'name': name_pattern(module.params.get('name'), module), u'name': name_pattern(module.params.get('name'), module),
u'kmsKeyName': module.params.get('kms_key_name'), u'kmsKeyName': module.params.get('kms_key_name'),
u'labels': module.params.get('labels'), u'labels': module.params.get('labels'),
u'messageStoragePolicy': TopicMessagestoragepolicy(module.params.get('message_storage_policy', {}), module).to_request(),
} }
return_vals = {} return_vals = {}
for k, v in request.items(): for k, v in request.items():
@ -254,7 +292,12 @@ def is_different(module, response):
# Remove unnecessary properties from the response. # Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters. # This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response): def response_to_hash(module, response):
return {u'name': name_pattern(module.params.get('name'), module), u'kmsKeyName': module.params.get('kms_key_name'), u'labels': response.get(u'labels')} return {
u'name': name_pattern(module.params.get('name'), module),
u'kmsKeyName': module.params.get('kms_key_name'),
u'labels': response.get(u'labels'),
u'messageStoragePolicy': TopicMessagestoragepolicy(response.get(u'messageStoragePolicy', {}), module).from_response(),
}
def name_pattern(name, module): def name_pattern(name, module):
@ -269,5 +312,20 @@ def name_pattern(name, module):
return name return name
class TopicMessagestoragepolicy(object):
def __init__(self, request, module):
self.module = module
if request:
self.request = request
else:
self.request = {}
def to_request(self):
return remove_nones_from_dict({u'allowedPersistenceRegions': self.request.get('allowed_persistence_regions')})
def from_response(self):
return remove_nones_from_dict({u'allowedPersistenceRegions': self.request.get(u'allowedPersistenceRegions')})
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -78,6 +78,23 @@ resources:
- A set of key/value label pairs to assign to this Topic. - A set of key/value label pairs to assign to this Topic.
returned: success returned: success
type: dict type: dict
messageStoragePolicy:
description:
- Policy constraining the set of Google Cloud Platform regions where messages
published to the topic may be stored. If not present, then no constraints
are in effect.
returned: success
type: complex
contains:
allowedPersistenceRegions:
description:
- A list of IDs of GCP regions where messages that are published to the
topic may be persisted in storage. Messages published by publishers running
in non-allowed GCP regions (or running outside of GCP altogether) will
be routed for storage in one of the allowed regions. An empty list means
that no regions are allowed, and is not a valid configuration.
returned: success
type: list
''' '''
################################################################################ ################################################################################

View file

@ -99,9 +99,9 @@ options:
type: int type: int
redis_version: redis_version:
description: description:
- The version of Redis software. If not provided, latest supported version will - 'The version of Redis software. If not provided, latest supported version will
be used. Updating the version will perform an upgrade/downgrade to the new version. be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0 compatibility
Currently, the supported values are REDIS_3_2 for Redis 3.2. - REDIS_3_2 for Redis 3.2 compatibility .'
required: false required: false
type: str type: str
reserved_ip_range: reserved_ip_range:
@ -236,9 +236,9 @@ port:
type: int type: int
redisVersion: redisVersion:
description: description:
- The version of Redis software. If not provided, latest supported version will - 'The version of Redis software. If not provided, latest supported version will
be used. Updating the version will perform an upgrade/downgrade to the new version. be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0 compatibility
Currently, the supported values are REDIS_3_2 for Redis 3.2. - REDIS_3_2 for Redis 3.2 compatibility .'
returned: success returned: success
type: str type: str
reservedIpRange: reservedIpRange:

View file

@ -142,9 +142,9 @@ resources:
type: int type: int
redisVersion: redisVersion:
description: description:
- The version of Redis software. If not provided, latest supported version will - 'The version of Redis software. If not provided, latest supported version
be used. Updating the version will perform an upgrade/downgrade to the new will be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0
version. Currently, the supported values are REDIS_3_2 for Redis 3.2. compatibility - REDIS_3_2 for Redis 3.2 compatibility .'
returned: success returned: success
type: str type: str
reservedIpRange: reservedIpRange: