* fix documentation and correct exception handling * follow AWS exception guidelines * fix parameter_group_family req; only needed when creating cache parameter group make pep8 and remove from legacy files
This commit is contained in:
parent
fcaa49b536
commit
e13fc5d6bd
2 changed files with 22 additions and 14 deletions
|
@ -32,8 +32,9 @@ options:
|
||||||
group_family:
|
group_family:
|
||||||
description:
|
description:
|
||||||
- The name of the cache parameter group family that the cache parameter group can be used with.
|
- The name of the cache parameter group family that the cache parameter group can be used with.
|
||||||
|
Required when creating a cache parameter group.
|
||||||
choices: ['memcached1.4', 'redis2.6', 'redis2.8', 'redis3.2']
|
choices: ['memcached1.4', 'redis2.6', 'redis2.8', 'redis3.2']
|
||||||
required: yes
|
required: no
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- A user-specified name for the cache parameter group.
|
- A user-specified name for the cache parameter group.
|
||||||
|
@ -48,7 +49,7 @@ options:
|
||||||
required: true
|
required: true
|
||||||
values:
|
values:
|
||||||
description:
|
description:
|
||||||
- A user-specified list of parameters to reset or modify for the cache parameter group.
|
- A user-specified dictionary of parameters to reset or modify for the cache parameter group.
|
||||||
required: no
|
required: no
|
||||||
default: None
|
default: None
|
||||||
"""
|
"""
|
||||||
|
@ -70,8 +71,8 @@ EXAMPLES = """
|
||||||
elasticache_parameter_group:
|
elasticache_parameter_group:
|
||||||
name: 'test-param-group'
|
name: 'test-param-group'
|
||||||
values:
|
values:
|
||||||
- ['activerehashing', 'yes']
|
activerehashing: yes
|
||||||
- ['client-output-buffer-limit-normal-hard-limit', 4]
|
client-output-buffer-limit-normal-hard-limit: 4
|
||||||
state: 'present'
|
state: 'present'
|
||||||
- name: 'Reset all modifiable parameters for the test parameter group'
|
- name: 'Reset all modifiable parameters for the test parameter group'
|
||||||
elasticache_parameter_group:
|
elasticache_parameter_group:
|
||||||
|
@ -123,25 +124,28 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_BOTO3 = False
|
HAS_BOTO3 = False
|
||||||
|
|
||||||
|
|
||||||
def create(module, conn, name, group_family, description):
|
def create(module, conn, name, group_family, description):
|
||||||
""" Create ElastiCache parameter group. """
|
""" Create ElastiCache parameter group. """
|
||||||
try:
|
try:
|
||||||
response = conn.create_cache_parameter_group(CacheParameterGroupName=name, CacheParameterGroupFamily=group_family, Description=description)
|
response = conn.create_cache_parameter_group(CacheParameterGroupName=name, CacheParameterGroupFamily=group_family, Description=description)
|
||||||
changed = True
|
changed = True
|
||||||
except boto.exception.BotoServerError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg="Unable to create cache parameter group.", exception=traceback.format_exc())
|
module.fail_json(msg="Unable to create cache parameter group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
return response, changed
|
return response, changed
|
||||||
|
|
||||||
|
|
||||||
def delete(module, conn, name):
|
def delete(module, conn, name):
|
||||||
""" Delete ElastiCache parameter group. """
|
""" Delete ElastiCache parameter group. """
|
||||||
try:
|
try:
|
||||||
conn.delete_cache_parameter_group(CacheParameterGroupName=name)
|
conn.delete_cache_parameter_group(CacheParameterGroupName=name)
|
||||||
response = {}
|
response = {}
|
||||||
changed = True
|
changed = True
|
||||||
except boto.exception.BotoServerError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg="Unable to delete cache parameter group.", exception=traceback.format_exc())
|
module.fail_json(msg="Unable to delete cache parameter group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
return response, changed
|
return response, changed
|
||||||
|
|
||||||
|
|
||||||
def make_current_modifiable_param_dict(module, conn, name):
|
def make_current_modifiable_param_dict(module, conn, name):
|
||||||
""" Gets the current state of the cache parameter group and creates a dict with the format: {ParameterName: [Allowed_Values, DataType, ParameterValue]}"""
|
""" Gets the current state of the cache parameter group and creates a dict with the format: {ParameterName: [Allowed_Values, DataType, ParameterValue]}"""
|
||||||
current_info = get_info(conn, name)
|
current_info = get_info(conn, name)
|
||||||
|
@ -156,6 +160,7 @@ def make_current_modifiable_param_dict(module, conn, name):
|
||||||
modifiable_params[param["ParameterName"]] = [param["AllowedValues"], param["DataType"], param["ParameterValue"]]
|
modifiable_params[param["ParameterName"]] = [param["AllowedValues"], param["DataType"], param["ParameterValue"]]
|
||||||
return modifiable_params
|
return modifiable_params
|
||||||
|
|
||||||
|
|
||||||
def check_valid_modification(module, values, modifiable_params):
|
def check_valid_modification(module, values, modifiable_params):
|
||||||
""" Check if the parameters and values in values are valid. """
|
""" Check if the parameters and values in values are valid. """
|
||||||
changed_with_update = False
|
changed_with_update = False
|
||||||
|
@ -184,6 +189,7 @@ def check_valid_modification(module, values, modifiable_params):
|
||||||
|
|
||||||
return changed_with_update
|
return changed_with_update
|
||||||
|
|
||||||
|
|
||||||
def check_changed_parameter_values(values, old_parameters, new_parameters):
|
def check_changed_parameter_values(values, old_parameters, new_parameters):
|
||||||
""" Checking if the new values are different than the old values. """
|
""" Checking if the new values are different than the old values. """
|
||||||
changed_with_update = False
|
changed_with_update = False
|
||||||
|
@ -203,6 +209,7 @@ def check_changed_parameter_values(values, old_parameters, new_parameters):
|
||||||
|
|
||||||
return changed_with_update
|
return changed_with_update
|
||||||
|
|
||||||
|
|
||||||
def modify(module, conn, name, values):
|
def modify(module, conn, name, values):
|
||||||
""" Modify ElastiCache parameter group to reflect the new information if it differs from the current. """
|
""" Modify ElastiCache parameter group to reflect the new information if it differs from the current. """
|
||||||
# compares current group parameters with the parameters we've specified to to a value to see if this will change the group
|
# compares current group parameters with the parameters we've specified to to a value to see if this will change the group
|
||||||
|
@ -212,10 +219,11 @@ def modify(module, conn, name, values):
|
||||||
format_parameters.append({'ParameterName': key, 'ParameterValue': value})
|
format_parameters.append({'ParameterName': key, 'ParameterValue': value})
|
||||||
try:
|
try:
|
||||||
response = conn.modify_cache_parameter_group(CacheParameterGroupName=name, ParameterNameValues=format_parameters)
|
response = conn.modify_cache_parameter_group(CacheParameterGroupName=name, ParameterNameValues=format_parameters)
|
||||||
except boto.exception.BotoServerError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg="Unable to modify cache parameter group.", exception=traceback.format_exc())
|
module.fail_json(msg="Unable to modify cache parameter group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def reset(module, conn, name, values):
|
def reset(module, conn, name, values):
|
||||||
""" Reset ElastiCache parameter group if the current information is different from the new information. """
|
""" Reset ElastiCache parameter group if the current information is different from the new information. """
|
||||||
# used to compare with the reset parameters' dict to see if there have been changes
|
# used to compare with the reset parameters' dict to see if there have been changes
|
||||||
|
@ -235,8 +243,8 @@ def reset(module, conn, name, values):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = conn.reset_cache_parameter_group(CacheParameterGroupName=name, ParameterNameValues=format_parameters, ResetAllParameters=all_parameters)
|
response = conn.reset_cache_parameter_group(CacheParameterGroupName=name, ParameterNameValues=format_parameters, ResetAllParameters=all_parameters)
|
||||||
except boto.exception.BotoServerError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
module.fail_json(msg="Unable to reset cache parameter group.", exception=traceback.format_exc())
|
module.fail_json(msg="Unable to reset cache parameter group.", exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||||
|
|
||||||
# determine changed
|
# determine changed
|
||||||
new_parameters_dict = make_current_modifiable_param_dict(module, conn, name)
|
new_parameters_dict = make_current_modifiable_param_dict(module, conn, name)
|
||||||
|
@ -244,6 +252,7 @@ def reset(module, conn, name, values):
|
||||||
|
|
||||||
return response, changed
|
return response, changed
|
||||||
|
|
||||||
|
|
||||||
def get_info(conn, name):
|
def get_info(conn, name):
|
||||||
""" Gets info about the ElastiCache parameter group. Returns false if it doesn't exist or we don't have access. """
|
""" Gets info about the ElastiCache parameter group. Returns false if it doesn't exist or we don't have access. """
|
||||||
try:
|
try:
|
||||||
|
@ -287,7 +296,7 @@ def main():
|
||||||
exists = get_info(connection, parameter_group_name)
|
exists = get_info(connection, parameter_group_name)
|
||||||
|
|
||||||
# check that the needed requirements are available
|
# check that the needed requirements are available
|
||||||
if state == 'present' and not exists and not (parameter_group_family or group_description):
|
if state == 'present' and not (exists and parameter_group_family and group_description):
|
||||||
module.fail_json(msg="Creating a group requires a family group and a description.")
|
module.fail_json(msg="Creating a group requires a family group and a description.")
|
||||||
elif state == 'reset' and not exists:
|
elif state == 'reset' and not exists:
|
||||||
module.fail_json(msg="No group %s to reset. Please create the group before using the state 'reset'." % parameter_group_name)
|
module.fail_json(msg="No group %s to reset. Please create the group before using the state 'reset'." % parameter_group_name)
|
||||||
|
|
|
@ -189,7 +189,6 @@ lib/ansible/modules/cloud/amazon/ecs_taskdefinition.py
|
||||||
lib/ansible/modules/cloud/amazon/efs.py
|
lib/ansible/modules/cloud/amazon/efs.py
|
||||||
lib/ansible/modules/cloud/amazon/efs_facts.py
|
lib/ansible/modules/cloud/amazon/efs_facts.py
|
||||||
lib/ansible/modules/cloud/amazon/elasticache.py
|
lib/ansible/modules/cloud/amazon/elasticache.py
|
||||||
lib/ansible/modules/cloud/amazon/elasticache_parameter_group.py
|
|
||||||
lib/ansible/modules/cloud/amazon/elasticache_snapshot.py
|
lib/ansible/modules/cloud/amazon/elasticache_snapshot.py
|
||||||
lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py
|
lib/ansible/modules/cloud/amazon/elasticache_subnet_group.py
|
||||||
lib/ansible/modules/cloud/amazon/execute_lambda.py
|
lib/ansible/modules/cloud/amazon/execute_lambda.py
|
||||||
|
|
Loading…
Reference in a new issue