Bug fixes for GCP modules (#60340)
This commit is contained in:
parent
1b45abc4f3
commit
5d4c3ad97e
4 changed files with 86 additions and 11 deletions
|
@ -68,6 +68,24 @@ options:
|
|||
required: false
|
||||
type: dict
|
||||
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
|
||||
notes:
|
||||
- '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.
|
||||
returned: success
|
||||
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
|
||||
################################################################################
|
||||
|
||||
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 re
|
||||
|
||||
|
@ -127,6 +161,7 @@ def main():
|
|||
name=dict(required=True, type='str'),
|
||||
kms_key_name=dict(type='str'),
|
||||
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 = []
|
||||
if request.get('labels') != response.get('labels'):
|
||||
update_mask.append('labels')
|
||||
if request.get('messageStoragePolicy') != response.get('messageStoragePolicy'):
|
||||
update_mask.append('messageStoragePolicy')
|
||||
return ','.join(update_mask)
|
||||
|
||||
|
||||
|
@ -190,6 +227,7 @@ def resource_to_request(module):
|
|||
u'name': name_pattern(module.params.get('name'), module),
|
||||
u'kmsKeyName': module.params.get('kms_key_name'),
|
||||
u'labels': module.params.get('labels'),
|
||||
u'messageStoragePolicy': TopicMessagestoragepolicy(module.params.get('message_storage_policy', {}), module).to_request(),
|
||||
}
|
||||
return_vals = {}
|
||||
for k, v in request.items():
|
||||
|
@ -254,7 +292,12 @@ def is_different(module, response):
|
|||
# Remove unnecessary properties from the response.
|
||||
# This is for doing comparisons with Ansible's current parameters.
|
||||
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):
|
||||
|
@ -269,5 +312,20 @@ def name_pattern(name, module):
|
|||
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__':
|
||||
main()
|
||||
|
|
|
@ -78,6 +78,23 @@ resources:
|
|||
- A set of key/value label pairs to assign to this Topic.
|
||||
returned: success
|
||||
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
|
||||
'''
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -99,9 +99,9 @@ options:
|
|||
type: int
|
||||
redis_version:
|
||||
description:
|
||||
- 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.
|
||||
Currently, the supported values are REDIS_3_2 for Redis 3.2.
|
||||
- 'The version of Redis software. If not provided, latest supported version will
|
||||
be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0 compatibility
|
||||
- REDIS_3_2 for Redis 3.2 compatibility .'
|
||||
required: false
|
||||
type: str
|
||||
reserved_ip_range:
|
||||
|
@ -236,9 +236,9 @@ port:
|
|||
type: int
|
||||
redisVersion:
|
||||
description:
|
||||
- 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.
|
||||
Currently, the supported values are REDIS_3_2 for Redis 3.2.
|
||||
- 'The version of Redis software. If not provided, latest supported version will
|
||||
be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0 compatibility
|
||||
- REDIS_3_2 for Redis 3.2 compatibility .'
|
||||
returned: success
|
||||
type: str
|
||||
reservedIpRange:
|
||||
|
|
|
@ -142,9 +142,9 @@ resources:
|
|||
type: int
|
||||
redisVersion:
|
||||
description:
|
||||
- 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. Currently, the supported values are REDIS_3_2 for Redis 3.2.
|
||||
- 'The version of Redis software. If not provided, latest supported version
|
||||
will be used. Currently, the supported values are: - REDIS_4_0 for Redis 4.0
|
||||
compatibility - REDIS_3_2 for Redis 3.2 compatibility .'
|
||||
returned: success
|
||||
type: str
|
||||
reservedIpRange:
|
||||
|
|
Loading…
Reference in a new issue