1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix few bugs around renaming db instances.

This commit is contained in:
Denver Janke 2014-09-04 16:13:09 +10:00 committed by Matt Clay
parent daac0e3a3e
commit 61cfccff1c

View file

@ -753,11 +753,10 @@ def facts_db_instance_or_snapshot(module, conn):
def modify_db_instance(module, conn): def modify_db_instance(module, conn):
required_vars = ['instance_name'] required_vars = ['instance_name']
valid_vars = ['backup_retention', 'backup_window', 'db_name', 'engine_version', valid_vars = ['apply_immediately', 'backup_retention', 'backup_window',
'instance_type', 'iops', 'license_model', 'maint_window', 'db_name', 'engine_version', 'instance_type', 'iops', 'license_model',
'password', 'multi_zone', 'new_instance_name', 'maint_window', 'multi_zone', 'new_instance_name',
'option_group', 'parameter_group', 'option_group', 'parameter_group' 'password', 'size', 'upgrade']
'size', 'upgrade']
params = validate_parameters(required_vars, valid_vars, module) params = validate_parameters(required_vars, valid_vars, module)
instance_name = module.params.get('instance_name') instance_name = module.params.get('instance_name')
@ -770,28 +769,15 @@ def modify_db_instance(module, conn):
if params.get('apply_immediately'): if params.get('apply_immediately'):
if new_instance_name: if new_instance_name:
# Wait until the new instance name is valid # Wait until the new instance name is valid
found = 0 new_instance = None
while found == 0: while not new_instance:
if has_rds2: new_instance = conn.get_db_instance(new_instance_name)
instances = conn.describe_all_db_instances() time.sleep(5)
else:
instances = conn.get_all_dbinstances()
for i in instances:
if i.id == new_instance_name:
instance_name = new_instance_name
found = 1
if found == 0:
time.sleep(5)
# The name of the database has now changed, so we have # Found instance but it briefly flicks to available
# to force result to contain the new instance, otherwise # before rebooting so let's wait until we see it rebooting
# the call below to get_current_resource will fail since it # before we check whether to 'wait'
# will be looking for the old instance name. result = await_resource(conn, new_instance, 'rebooting', module)
result.id = new_instance_name
else:
# Wait for a few seconds since it takes a while for AWS
# to change the instance from 'available' to 'modifying'
time.sleep(5)
if module.params.get('wait'): if module.params.get('wait'):
resource = await_resource(conn, result, 'available', module) resource = await_resource(conn, result, 'available', module)
@ -918,6 +904,7 @@ def validate_parameters(required_vars, valid_vars, module):
'character_set_name': 'character_set_name', 'character_set_name': 'character_set_name',
'instance_type': 'db_instance_class', 'instance_type': 'db_instance_class',
'password': 'master_user_password', 'password': 'master_user_password',
'new_instance_name': 'new_db_instance_identifier',
} }
if has_rds2: if has_rds2:
optional_params.update(optional_params_rds2) optional_params.update(optional_params_rds2)
@ -977,7 +964,7 @@ def main():
zone = dict(aliases=['aws_zone', 'ec2_zone'], required=False), zone = dict(aliases=['aws_zone', 'ec2_zone'], required=False),
subnet = dict(required=False), subnet = dict(required=False),
wait = dict(type='bool', default=False), wait = dict(type='bool', default=False),
wait_timeout = dict(default=300), wait_timeout = dict(type='int', default=300),
snapshot = dict(required=False), snapshot = dict(required=False),
apply_immediately = dict(type='bool', default=False), apply_immediately = dict(type='bool', default=False),
new_instance_name = dict(required=False), new_instance_name = dict(required=False),