diff --git a/moto/rds2/models.py b/moto/rds2/models.py index 5abd2ed1b..6ae0c98a0 100644 --- a/moto/rds2/models.py +++ b/moto/rds2/models.py @@ -733,6 +733,37 @@ class RDS2Backend(BaseBackend): database = self.describe_databases(db_instance_identifier)[0] return database + def _check_can_stop_rds_instance_(self, database=None): + # todo: certain rds types not allowed to be stopped at this time. + if database: + if database.is_replica or database.multi_az: + # should be 400 error + return RDSClientError('InvalidDBClusterStateFault', 'Invalid DB type, when trying to perform StopDBInstance. See AWS RDS documentation on rds.stop_db_instance') + return True + + def stop_database(self, db_instance_identifier, snapshot_name=None): + database = self.describe_databases(db_instance_identifier)[0] + self._check_can_stop_rds_instance_(database) + if database.status != 'available': + return RDSClientError('InvalidDBInstanceState', 'when calling the StopDBInstance operation: Instance testdb is not in available state') + self.create_rds_snapshot(db_instance_identifier, db_instance_identifier) + database.status = 'shutdown' + return database + + def start_database(self, db_instance_identifier): + database = self.describe_databases(db_instance_identifier)[0] + if database.status != 'shutdown': + # should be 400 error + return RDSClientError('InvalidDBInstanceState', 'when calling the StartDBInstance operation: Instance {} is not stopped, it cannot be started.' % db_instance_identifier) + database.status = 'available' + return + + def create_rds_snapshot(self, db_instance_identifier, db_snapshot_identifier): + # todo + # DBSnapshotAlreadyExists + # SnapshotQuotaExceeded + return None + def find_db_from_id(self, db_id): if self.arn_regex.match(db_id): arn_breakdown = db_id.split(':') diff --git a/moto/rds2/responses.py b/moto/rds2/responses.py index ef02bfbf1..d8108c7f8 100644 --- a/moto/rds2/responses.py +++ b/moto/rds2/responses.py @@ -23,6 +23,7 @@ class RDS2Response(BaseResponse): "db_instance_identifier": self._get_param('DBInstanceIdentifier'), "db_name": self._get_param("DBName"), "db_parameter_group_name": self._get_param("DBParameterGroupName"), + "db_snapshot_identifier": self._get_param('DBSnapshotIdentifier'), "db_subnet_group_name": self._get_param("DBSubnetGroupName"), "engine": self._get_param("Engine"), "engine_version": self._get_param("EngineVersion"), @@ -193,6 +194,19 @@ class RDS2Response(BaseResponse): template = self.response_template(REMOVE_TAGS_FROM_RESOURCE_TEMPLATE) return template.render() + def stop_db_instance(self): + db_instance_identifier = self._get_param('DBInstanceIdentifier') + db_snapshot_identifier = self._get_param('DBInstanceIdentifier') + database = self.backend.stop_database(db_instance_identifier, db_snapshot_identifier) + template = self.response_template(STOP_DATABASE_TEMPLATE) + return template.render(database=database) + + def start_db_instance(self): + db_instance_identifier = self._get_param('DBInstanceIdentifier') + database = self.backend.start_database(db_instance_identifier) + template = self.response_template(START_DATABASE_TEMPLATE) + return template.render(database=database) + def create_db_security_group(self): group_name = self._get_param('DBSecurityGroupName') description = self._get_param('DBSecurityGroupDescription') @@ -410,8 +424,25 @@ REBOOT_DATABASE_TEMPLATE = """ + + {{ database.to_xml() }} + + + 523e3218-afc7-11c3-90f5-f90431260ab9 + +""" -DELETE_DATABASE_TEMPLATE = """ +STOP_DATABASE_TEMPLATE = """ + + {{ database.to_xml() }} + + + 523e3218-afc7-11c3-90f5-f90431260ab8 + +""" + +DELETE_DATABASE_TEMPLATE = """ {{ database.to_xml() }} @@ -420,7 +451,7 @@ DELETE_DATABASE_TEMPLATE = """ +CREATE_SNAPSHOT_TEMPLATE = """ {{ snapshot.to_xml() }}