rds: do not update multi-az unless specified - fixes #23385 (#23498)

* allow multi_az to be unmodified if not explicitly specified

* fix pep8 and remove from legacy files
pull/24256/head
Sloane Hertel 8 years ago committed by GitHub
parent fb6e9e8fbe
commit ad8cb903f4

@ -340,7 +340,7 @@ try:
except ImportError: except ImportError:
has_rds2 = False has_rds2 = False
DEFAULT_PORTS= { DEFAULT_PORTS = {
'aurora': 3306, 'aurora': 3306,
'mariadb': 3306, 'mariadb': 3306,
'mysql': 3306, 'mysql': 3306,
@ -349,6 +349,7 @@ DEFAULT_PORTS= {
'postgres': 5432, 'postgres': 5432,
} }
class RDSException(Exception): class RDSException(Exception):
def __init__(self, exc): def __init__(self, exc):
if hasattr(exc, 'error_message') and exc.error_message: if hasattr(exc, 'error_message') and exc.error_message:
@ -365,7 +366,7 @@ class RDSException(Exception):
class RDSConnection: class RDSConnection:
def __init__(self, module, region, **aws_connect_params): def __init__(self, module, region, **aws_connect_params):
try: try:
self.connection = connect_to_aws(boto.rds, region, **aws_connect_params) self.connection = connect_to_aws(boto.rds, region, **aws_connect_params)
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError as e:
module.fail_json(msg=e.error_message) module.fail_json(msg=e.error_message)
@ -382,11 +383,11 @@ class RDSConnection:
return None return None
def create_db_instance(self, instance_name, size, instance_class, db_engine, def create_db_instance(self, instance_name, size, instance_class, db_engine,
username, password, **params): username, password, **params):
params['engine'] = db_engine params['engine'] = db_engine
try: try:
result = self.connection.create_dbinstance(instance_name, size, instance_class, result = self.connection.create_dbinstance(instance_name, size, instance_class,
username, password, **params) username, password, **params)
return RDSDBInstance(result) return RDSDBInstance(result)
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError as e:
raise RDSException(e) raise RDSException(e)
@ -451,7 +452,7 @@ class RDSConnection:
class RDS2Connection: class RDS2Connection:
def __init__(self, module, region, **aws_connect_params): def __init__(self, module, region, **aws_connect_params):
try: try:
self.connection = connect_to_aws(boto.rds2, region, **aws_connect_params) self.connection = connect_to_aws(boto.rds2, region, **aws_connect_params)
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError as e:
module.fail_json(msg=e.error_message) module.fail_json(msg=e.error_message)
@ -460,7 +461,7 @@ class RDS2Connection:
dbinstances = self.connection.describe_db_instances( dbinstances = self.connection.describe_db_instances(
db_instance_identifier=instancename db_instance_identifier=instancename
)['DescribeDBInstancesResponse']['DescribeDBInstancesResult']['DBInstances'] )['DescribeDBInstancesResponse']['DescribeDBInstancesResult']['DBInstances']
result = RDS2DBInstance(dbinstances[0]) result = RDS2DBInstance(dbinstances[0])
return result return result
except boto.rds2.exceptions.DBInstanceNotFound as e: except boto.rds2.exceptions.DBInstanceNotFound as e:
return None return None
@ -479,10 +480,10 @@ class RDS2Connection:
return None return None
def create_db_instance(self, instance_name, size, instance_class, db_engine, def create_db_instance(self, instance_name, size, instance_class, db_engine,
username, password, **params): username, password, **params):
try: try:
result = self.connection.create_db_instance(instance_name, size, instance_class, result = self.connection.create_db_instance(instance_name, size, instance_class, db_engine, username, password,
db_engine, username, password, **params)['CreateDBInstanceResponse']['CreateDBInstanceResult']['DBInstance'] **params)['CreateDBInstanceResponse']['CreateDBInstanceResult']['DBInstance']
return RDS2DBInstance(result) return RDS2DBInstance(result)
except boto.exception.BotoServerError as e: except boto.exception.BotoServerError as e:
raise RDSException(e) raise RDSException(e)
@ -560,18 +561,18 @@ class RDSDBInstance:
def get_data(self): def get_data(self):
d = { d = {
'id' : self.name, 'id': self.name,
'create_time' : self.instance.create_time, 'create_time': self.instance.create_time,
'status' : self.status, 'status': self.status,
'availability_zone' : self.instance.availability_zone, 'availability_zone': self.instance.availability_zone,
'backup_retention' : self.instance.backup_retention_period, 'backup_retention': self.instance.backup_retention_period,
'backup_window' : self.instance.preferred_backup_window, 'backup_window': self.instance.preferred_backup_window,
'maintenance_window' : self.instance.preferred_maintenance_window, 'maintenance_window': self.instance.preferred_maintenance_window,
'multi_zone' : self.instance.multi_az, 'multi_zone': self.instance.multi_az,
'instance_type' : self.instance.instance_class, 'instance_type': self.instance.instance_class,
'username' : self.instance.master_username, 'username': self.instance.master_username,
'iops' : self.instance.iops 'iops': self.instance.iops
} }
# Only assign an Endpoint if one is available # Only assign an Endpoint if one is available
if hasattr(self.instance, 'endpoint'): if hasattr(self.instance, 'endpoint'):
@ -594,8 +595,6 @@ class RDSDBInstance:
return d return d
class RDS2DBInstance: class RDS2DBInstance:
def __init__(self, dbinstance): def __init__(self, dbinstance):
self.instance = dbinstance self.instance = dbinstance
@ -639,12 +638,12 @@ class RDSSnapshot:
def get_data(self): def get_data(self):
d = { d = {
'id' : self.name, 'id': self.name,
'create_time' : self.snapshot.snapshot_create_time, 'create_time': self.snapshot.snapshot_create_time,
'status' : self.status, 'status': self.status,
'availability_zone' : self.snapshot.availability_zone, 'availability_zone': self.snapshot.availability_zone,
'instance_id' : self.snapshot.instance_id, 'instance_id': self.snapshot.instance_id,
'instance_created' : self.snapshot.instance_create_time, 'instance_created': self.snapshot.instance_create_time,
} }
# needs boto >= 2.21.0 # needs boto >= 2.21.0
if hasattr(self.snapshot, 'snapshot_type'): if hasattr(self.snapshot, 'snapshot_type'):
@ -665,14 +664,14 @@ class RDS2Snapshot:
def get_data(self): def get_data(self):
d = { d = {
'id' : self.name, 'id': self.name,
'create_time' : self.snapshot['SnapshotCreateTime'], 'create_time': self.snapshot['SnapshotCreateTime'],
'status' : self.status, 'status': self.status,
'availability_zone' : self.snapshot['AvailabilityZone'], 'availability_zone': self.snapshot['AvailabilityZone'],
'instance_id' : self.snapshot['DBInstanceIdentifier'], 'instance_id': self.snapshot['DBInstanceIdentifier'],
'instance_created' : self.snapshot['InstanceCreateTime'], 'instance_created': self.snapshot['InstanceCreateTime'],
'snapshot_type' : self.snapshot['SnapshotType'], 'snapshot_type': self.snapshot['SnapshotType'],
'iops' : self.snapshot['Iops'], 'iops': self.snapshot['Iops'],
} }
return d return d
@ -712,7 +711,7 @@ def create_db_instance(module, conn):
valid_vars = ['backup_retention', 'backup_window', valid_vars = ['backup_retention', 'backup_window',
'character_set_name', 'db_name', 'engine_version', 'character_set_name', 'db_name', 'engine_version',
'instance_type', 'iops', 'license_model', 'maint_window', 'instance_type', 'iops', 'license_model', 'maint_window',
'multi_zone', 'option_group', 'parameter_group','port', 'multi_zone', 'option_group', 'parameter_group', 'port',
'subnet', 'upgrade', 'zone'] 'subnet', 'upgrade', 'zone']
if module.params.get('subnet'): if module.params.get('subnet'):
valid_vars.append('vpc_security_groups') valid_vars.append('vpc_security_groups')
@ -729,8 +728,8 @@ def create_db_instance(module, conn):
else: else:
try: try:
result = conn.create_db_instance(instance_name, module.params.get('size'), result = conn.create_db_instance(instance_name, module.params.get('size'),
module.params.get('instance_type'), module.params.get('db_engine'), module.params.get('instance_type'), module.params.get('db_engine'),
module.params.get('username'), module.params.get('password'), **params) module.params.get('username'), module.params.get('password'), **params)
changed = True changed = True
except RDSException as e: except RDSException as e:
module.fail_json(msg="Failed to create instance: %s" % e.message) module.fail_json(msg="Failed to create instance: %s" % e.message)
@ -1068,40 +1067,40 @@ def validate_parameters(required_vars, valid_vars, module):
def main(): def main():
argument_spec = ec2_argument_spec() argument_spec = ec2_argument_spec()
argument_spec.update(dict( argument_spec.update(dict(
command = dict(choices=['create', 'replicate', 'delete', 'facts', 'modify', 'promote', 'snapshot', 'reboot', 'restore'], required=True), command=dict(choices=['create', 'replicate', 'delete', 'facts', 'modify', 'promote', 'snapshot', 'reboot', 'restore'], required=True),
instance_name = dict(required=False), instance_name=dict(required=False),
source_instance = dict(required=False), source_instance=dict(required=False),
db_engine = dict(choices=['mariadb', 'MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', db_engine=dict(choices=['mariadb', 'MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex',
'sqlserver-web', 'postgres', 'aurora'], required=False), 'sqlserver-web', 'postgres', 'aurora'], required=False),
size = dict(required=False), size=dict(required=False),
instance_type = dict(aliases=['type'], required=False), instance_type=dict(aliases=['type'], required=False),
username = dict(required=False), username=dict(required=False),
password = dict(no_log=True, required=False), password=dict(no_log=True, required=False),
db_name = dict(required=False), db_name=dict(required=False),
engine_version = dict(required=False), engine_version=dict(required=False),
parameter_group = dict(required=False), parameter_group=dict(required=False),
license_model = dict(choices=['license-included', 'bring-your-own-license', 'general-public-license', 'postgresql-license'], required=False), license_model=dict(choices=['license-included', 'bring-your-own-license', 'general-public-license', 'postgresql-license'], required=False),
multi_zone = dict(type='bool', default=False), multi_zone=dict(type='bool', required=False),
iops = dict(required=False), iops=dict(required=False),
security_groups = dict(required=False), security_groups=dict(required=False),
vpc_security_groups = dict(type='list', required=False), vpc_security_groups=dict(type='list', required=False),
port = dict(required=False), port=dict(required=False),
upgrade = dict(type='bool', default=False), upgrade=dict(type='bool', default=False),
option_group = dict(required=False), option_group=dict(required=False),
maint_window = dict(required=False), maint_window=dict(required=False),
backup_window = dict(required=False), backup_window=dict(required=False),
backup_retention = dict(required=False), backup_retention=dict(required=False),
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(type='int', 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),
tags = dict(type='dict', required=False), tags=dict(type='dict', required=False),
publicly_accessible = dict(required=False), publicly_accessible=dict(required=False),
character_set_name = dict(required=False), character_set_name=dict(required=False),
force_failover = dict(type='bool', required=False, default=False) force_failover=dict(type='bool', required=False, default=False)
) )
) )

@ -198,7 +198,6 @@ lib/ansible/modules/cloud/amazon/iam_policy.py
lib/ansible/modules/cloud/amazon/iam_server_certificate_facts.py lib/ansible/modules/cloud/amazon/iam_server_certificate_facts.py
lib/ansible/modules/cloud/amazon/lambda.py lib/ansible/modules/cloud/amazon/lambda.py
lib/ansible/modules/cloud/amazon/lambda_facts.py lib/ansible/modules/cloud/amazon/lambda_facts.py
lib/ansible/modules/cloud/amazon/rds.py
lib/ansible/modules/cloud/amazon/rds_param_group.py lib/ansible/modules/cloud/amazon/rds_param_group.py
lib/ansible/modules/cloud/amazon/rds_subnet_group.py lib/ansible/modules/cloud/amazon/rds_subnet_group.py
lib/ansible/modules/cloud/amazon/redshift.py lib/ansible/modules/cloud/amazon/redshift.py

Loading…
Cancel
Save