Fix few bugs around renaming db instances.

pull/18777/head
Denver Janke 10 years ago committed by Matt Clay
parent daac0e3a3e
commit 61cfccff1c

@ -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() # Found instance but it briefly flicks to available
for i in instances: # before rebooting so let's wait until we see it rebooting
if i.id == new_instance_name: # before we check whether to 'wait'
instance_name = new_instance_name result = await_resource(conn, new_instance, 'rebooting', module)
found = 1
if found == 0:
time.sleep(5)
# The name of the database has now changed, so we have
# to force result to contain the new instance, otherwise
# the call below to get_current_resource will fail since it
# will be looking for the old instance name.
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),

Loading…
Cancel
Save