<s> from __future__ import unicode_literals <EOL> from moto . core . responses import BaseResponse <EOL> from moto . ec2 . models import ec2_backends <EOL> from . models import rds2_backends <EOL> import json <EOL> import re <EOL> class RDS2Response ( BaseResponse ) : <EOL> @ property <EOL> def backend ( self ) : <EOL> return rds2_backends [ self . region ] <EOL> def _get_db_kwargs ( self ) : <EOL> args = { <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_int_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_int_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_bool_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT:port>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . region , <EOL> "<STR_LIT>" : self . _get_multi_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : list ( ) <EOL> } <EOL> args [ '<STR_LIT>' ] = self . unpack_complex_list_params ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> return args <EOL> def _get_db_replica_kwargs ( self ) : <EOL> return { <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_int_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT:port>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : self . _get_param ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : self . _get_param ( "<STR_LIT>" ) , <EOL> } <EOL> def _get_option_group_kwargs ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' ) , <EOL> '<STR_LIT:description>' : self . _get_param ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' ) , <EOL> '<STR_LIT:name>' : self . _get_param ( '<STR_LIT>' ) <EOL> } <EOL> def unpack_complex_list_params ( self , label , names ) : <EOL> unpacked_list = list ( ) <EOL> count = <NUM_LIT:1> <EOL> while self . _get_param ( '<STR_LIT>' . format ( label , count , names [ <NUM_LIT:0> ] ) ) : <EOL> param = dict ( ) <EOL> for i in range ( len ( names ) ) : <EOL> param [ names [ i ] ] = self . _get_param ( '<STR_LIT>' . format ( label , count , names [ i ] ) ) <EOL> unpacked_list . append ( param ) <EOL> count += <NUM_LIT:1> <EOL> return unpacked_list <EOL> def unpack_list_params ( self , label ) : <EOL> unpacked_list = list ( ) <EOL> count = <NUM_LIT:1> <EOL> while self . _get_param ( '<STR_LIT>' . format ( label , count ) ) : <EOL> unpacked_list . append ( self . _get_param ( '<STR_LIT>' . format ( label , count ) ) ) <EOL> count += <NUM_LIT:1> <EOL> return unpacked_list <EOL> def create_dbinstance ( self ) : <EOL> return self . create_db_instance ( ) <EOL> def create_db_instance ( self ) : <EOL> db_kwargs = self . _get_db_kwargs ( ) <EOL> database = self . backend . create_database ( db_kwargs ) <EOL> template = self . response_template ( CREATE_DATABASE_TEMPLATE ) <EOL> return template . render ( database = database ) <EOL> def create_dbinstance_read_replica ( self ) : <EOL> return self . create_db_instance_read_replica ( ) <EOL> def create_db_instance_read_replica ( self ) : <EOL> db_kwargs = self . _get_db_replica_kwargs ( ) <EOL> database = self . backend . create_database_replica ( db_kwargs ) <EOL> template = self . response_template ( CREATE_DATABASE_REPLICA_TEMPLATE ) <EOL> return template . render ( database = database ) <EOL> def describe_dbinstances ( self ) : <EOL> return self . describe_db_instances ( ) <EOL> def describe_db_instances ( self ) : <EOL> db_instance_identifier = self . _get_param ( '<STR_LIT>' ) <EOL> databases = self . backend . describe_databases ( db_instance_identifier ) <EOL> template = self . response_template ( DESCRIBE_DATABASES_TEMPLATE ) <EOL> return template . render ( databases = databases ) <EOL> def modify_dbinstance ( self ) : <EOL> return self . modify_db_instance ( ) <EOL> def modify_db_instance ( self ) : <EOL> db_instance_identifier = self . _get_param ( '<STR_LIT>' ) <EOL> db_kwargs = self . _get_db_kwargs ( ) <EOL> database = self . backend . modify_database ( db_instance_identifier , db_kwargs ) <EOL> template = self . response_template ( MODIFY_DATABASE_TEMPLATE ) <EOL> return template . render ( database = database ) <EOL> def delete_dbinstance ( self ) : <EOL> return self . delete_db_instance ( ) <EOL> def delete_db_instance ( self ) : <EOL> db_instance_identifier = self . _get_param ( '<STR_LIT>' ) <EOL> database = self . backend . delete_database ( db_instance_identifier ) <EOL> template = self . response_template ( DELETE_DATABASE_TEMPLATE ) <EOL> return template . render ( database = database ) <EOL> def reboot_dbinstance ( self ) : <EOL> return self . reboot_db_instance ( ) <EOL> def reboot_db_instance ( self ) : <EOL> db_instance_identifier = self . _get_param ( '<STR_LIT>' ) <EOL> database = self . backend . reboot_db_instance ( db_instance_identifier ) <EOL> template = self . response_template ( REBOOT_DATABASE_TEMPLATE ) <EOL> return template . render ( database = database ) <EOL> def list_tags_for_resource ( self ) : <EOL> arn = self . _get_param ( '<STR_LIT>' ) <EOL> template = self . response_template ( LIST_TAGS_FOR_RESOURCE_TEMPLATE ) <EOL> tags = self . backend . list_tags_for_resource ( arn ) <EOL> return template . render ( tags = tags ) <EOL> def add_tags_to_resource ( self ) : <EOL> arn = self . _get_param ( '<STR_LIT>' ) <EOL> tags = self . unpack_complex_list_params ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> tags = self . backend . add_tags_to_resource ( arn , tags ) <EOL> template = self . response_template ( ADD_TAGS_TO_RESOURCE_TEMPLATE ) <EOL> return template . render ( tags = tags ) <EOL> def remove_tags_from_resource ( self ) : <EOL> arn = self . _get_param ( '<STR_LIT>' ) <EOL> tag_keys = self . unpack_list_params ( '<STR_LIT>' ) <EOL> self . backend . remove_tags_from_resource ( arn , tag_keys ) <EOL> template = self . response_template ( REMOVE_TAGS_FROM_RESOURCE_TEMPLATE ) <EOL> return template . render ( ) <EOL> def create_dbsecurity_group ( self ) : <EOL> return self . create_db_security_group ( ) <EOL> def create_db_security_group ( self ) : <EOL> group_name = self . _get_param ( '<STR_LIT>' ) <EOL> description = self . _get_param ( '<STR_LIT>' ) <EOL> security_group = self . backend . create_security_group ( group_name , description ) <EOL> template = self . response_template ( CREATE_SECURITY_GROUP_TEMPLATE ) <EOL> return template . render ( security_group = security_group ) <EOL> def describe_dbsecurity_groups ( self ) : <EOL> return self . describe_db_security_groups ( ) <EOL> def describe_db_security_groups ( self ) : <EOL> security_group_name = self . _get_param ( '<STR_LIT>' ) <EOL> security_groups = self . backend . describe_security_groups ( security_group_name ) <EOL> template = self . response_template ( DESCRIBE_SECURITY_GROUPS_TEMPLATE ) <EOL> return template . render ( security_groups = security_groups ) <EOL> def delete_dbsecurity_group ( self ) : <EOL> return self . delete_db_security_group ( ) <EOL> def delete_db_security_group ( self ) : <EOL> security_group_name = self . _get_param ( '<STR_LIT>' ) <EOL> security_group = self . backend . delete_security_group ( security_group_name ) <EOL> template = self . response_template ( DELETE_SECURITY_GROUP_TEMPLATE ) <EOL> return template . render ( security_group = security_group ) <EOL> def authorize_dbsecurity_group_ingress ( self ) : <EOL> return self . authorize_db_security_group_ingress ( ) <EOL> def authorize_db_security_group_ingress ( self ) : <EOL> security_group_name = self . _get_param ( '<STR_LIT>' ) <EOL> cidr_ip = self . _get_param ( '<STR_LIT>' ) <EOL> security_group = self . backend . authorize_security_group ( security_group_name , cidr_ip ) <EOL> template = self . response_template ( AUTHORIZE_SECURITY_GROUP_TEMPLATE ) <EOL> return template . render ( security_group = security_group ) <EOL> def create_dbsubnet_group ( self ) : <EOL> return self . create_db_subnet_group ( ) <EOL> def create_db_subnet_group ( self ) : <EOL> subnet_name = self . _get_param ( '<STR_LIT>' ) <EOL> description = self . _get_param ( '<STR_LIT>' ) <EOL> subnet_ids = self . _get_multi_param ( '<STR_LIT>' ) <EOL> subnets = [ ec2_backends [ self . region ] . get_subnet ( subnet_id ) for subnet_id in subnet_ids ] <EOL> subnet_group = self . backend . create_subnet_group ( subnet_name , description , subnets ) <EOL> template = self . response_template ( CREATE_SUBNET_GROUP_TEMPLATE ) <EOL> return template . render ( subnet_group = subnet_group ) <EOL> def describe_dbsubnet_groups ( self ) : <EOL> return self . describe_db_subnet_groups ( ) <EOL> def describe_db_subnet_groups ( self ) : <EOL> subnet_name = self . _get_param ( '<STR_LIT>' ) <EOL> subnet_groups = self . backend . describe_subnet_groups ( subnet_name ) <EOL> template = self . response_template ( DESCRIBE_SUBNET_GROUPS_TEMPLATE ) <EOL> return template . render ( subnet_groups = subnet_groups ) <EOL> def delete_dbsubnet_group ( self ) : <EOL> return self . delete_db_subnet_group ( ) <EOL> def delete_db_subnet_group ( self ) : <EOL> subnet_name = self . _get_param ( '<STR_LIT>' ) <EOL> subnet_group = self . backend . delete_subnet_group ( subnet_name ) <EOL> template = self . response_template ( DELETE_SUBNET_GROUP_TEMPLATE ) <EOL> return template . render ( subnet_group = subnet_group ) <EOL> def create_option_group ( self ) : <EOL> kwargs = self . _get_option_group_kwargs ( ) <EOL> option_group = self . backend . create_option_group ( kwargs ) <EOL> template = self . response_template ( CREATE_OPTION_GROUP_TEMPLATE ) <EOL> return template . render ( option_group = option_group ) <EOL> def delete_option_group ( self ) : <EOL> kwargs = self . _get_option_group_kwargs ( ) <EOL> option_group = self . backend . delete_option_group ( kwargs [ '<STR_LIT:name>' ] ) <EOL> template = self . response_template ( DELETE_OPTION_GROUP_TEMPLATE ) <EOL> return template . render ( option_group = option_group ) <EOL> def describe_option_groups ( self ) : <EOL> kwargs = self . _get_option_group_kwargs ( ) <EOL> kwargs [ '<STR_LIT>' ] = self . _get_param ( '<STR_LIT>' ) <EOL> kwargs [ '<STR_LIT>' ] = self . _get_param ( '<STR_LIT>' ) <EOL> option_groups = self . backend . describe_option_groups ( kwargs ) <EOL> template = self . response_template ( DESCRIBE_OPTION_GROUP_TEMPLATE ) <EOL> return template . render ( option_groups = option_groups ) <EOL> def describe_option_group_options ( self ) : <EOL> engine_name = self . _get_param ( '<STR_LIT>' ) <EOL> major_engine_version = self . _get_param ( '<STR_LIT>' ) <EOL> option_group_options = self . backend . describe_option_group_options ( engine_name , major_engine_version ) <EOL> return option_group_options <EOL> def modify_option_group ( self ) : <EOL> option_group_name = self . _get_param ( '<STR_LIT>' ) <EOL> count = <NUM_LIT:1> <EOL> options_to_include = [ ] <EOL> while self . _get_param ( '<STR_LIT>' . format ( count ) ) : <EOL> options_to_include . append ( { <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' . format ( count ) ) , <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' . format ( count ) ) , <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' . format ( count ) ) , <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' . format ( count ) ) , <EOL> '<STR_LIT>' : self . _get_param ( '<STR_LIT>' . format ( count ) ) <EOL> } ) <EOL> count += <NUM_LIT:1> <EOL> count = <NUM_LIT:1> <EOL> options_to_remove = [ ] <EOL> while self . _get_param ( '<STR_LIT>' . format ( count ) ) : <EOL> options_to_remove . append ( self . _get_param ( '<STR_LIT>' . format ( count ) ) ) <EOL> count += <NUM_LIT:1> <EOL> apply_immediately = self . _get_param ( '<STR_LIT>' ) <EOL> option_group = self . backend . modify_option_group ( option_group_name , <EOL> options_to_include , <EOL> options_to_remove , <EOL> apply_immediately ) <EOL> template = self . response_template ( MODIFY_OPTION_GROUP_TEMPLATE ) <EOL> return template . render ( option_group = option_group ) <EOL> CREATE_DATABASE_TEMPLATE = """<STR_LIT>""" <EOL> CREATE_DATABASE_REPLICA_TEMPLATE = """<STR_LIT>""" <EOL> DESCRIBE_DATABASES_TEMPLATE = """<STR_LIT>""" <EOL> MODIFY_DATABASE_TEMPLATE = """<STR_LIT>""" <EOL> REBOOT_DATABASE_TEMPLATE = """<STR_LIT>""" <EOL> DELETE_DATABASE_TEMPLATE = """<STR_LIT>""" <EOL> CREATE_SECURITY_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> DESCRIBE_SECURITY_GROUPS_TEMPLATE = """<STR_LIT>""" <EOL> DELETE_SECURITY_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> AUTHORIZE_SECURITY_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> CREATE_SUBNET_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> DESCRIBE_SUBNET_GROUPS_TEMPLATE = """<STR_LIT>""" <EOL> DELETE_SUBNET_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> CREATE_OPTION_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> DELETE_OPTION_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> DESCRIBE_OPTION_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> DESCRIBE_OPTION_GROUP_OPTIONS_TEMPLATE = """<STR_LIT>""" <EOL> MODIFY_OPTION_GROUP_TEMPLATE = """<STR_LIT>""" <EOL> LIST_TAGS_FOR_RESOURCE_TEMPLATE = """<STR_LIT>""" <EOL> ADD_TAGS_TO_RESOURCE_TEMPLATE = """<STR_LIT>""" <EOL> REMOVE_TAGS_FROM_RESOURCE_TEMPLATE = """<STR_LIT>""" </s>
