Added reboot instance and list_tags_for_resource. Still need to get the tags populated.
This commit is contained in:
parent
23ff33b145
commit
6232abfe2d
4 changed files with 138 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ import copy
|
|||
import boto.rds2
|
||||
import json
|
||||
from jinja2 import Template
|
||||
|
||||
from re import compile as re_compile
|
||||
from moto.cloudformation.exceptions import UnformattedGetAttTemplateException
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.utils import get_random_hex
|
||||
|
|
@ -82,7 +82,7 @@ class Database(object):
|
|||
if not self.option_group_name and self.engine in self.default_option_groups:
|
||||
self.option_group_name = self.default_option_groups[self.engine]
|
||||
self.character_set_name = kwargs.get('character_set_name', None)
|
||||
self.tags = kwargs.get('tags', None)
|
||||
self.tags = kwargs.get('tags', [])
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
|
|
@ -242,6 +242,9 @@ class Database(object):
|
|||
}""")
|
||||
return template.render(database=self)
|
||||
|
||||
def get_tags(self):
|
||||
return self.tags
|
||||
|
||||
|
||||
class SecurityGroup(object):
|
||||
def __init__(self, group_name, description):
|
||||
|
|
@ -384,6 +387,7 @@ class SubnetGroup(object):
|
|||
class RDS2Backend(BaseBackend):
|
||||
|
||||
def __init__(self):
|
||||
self.arn_regex = re_compile(r'^arn:aws:rds:.*:[0-9]*:db:.*$')
|
||||
self.databases = {}
|
||||
self.security_groups = {}
|
||||
self.subnet_groups = {}
|
||||
|
|
@ -419,6 +423,10 @@ class RDS2Backend(BaseBackend):
|
|||
database.update(db_kwargs)
|
||||
return database
|
||||
|
||||
def reboot_db_instance(self, db_instance_identifier):
|
||||
database = self.describe_databases(db_instance_identifier)[0]
|
||||
return database
|
||||
|
||||
def delete_database(self, db_instance_identifier):
|
||||
if db_instance_identifier in self.databases:
|
||||
database = self.databases.pop(db_instance_identifier)
|
||||
|
|
@ -579,6 +587,17 @@ class RDS2Backend(BaseBackend):
|
|||
self.option_groups[option_group_name].add_options(options_to_include)
|
||||
return self.option_groups[option_group_name]
|
||||
|
||||
def list_tags_for_resource(self, arn):
|
||||
if self.arn_regex.match(arn):
|
||||
arn_breakdown = arn.split(':')
|
||||
db_instance_name = arn_breakdown[len(arn_breakdown)-1]
|
||||
if db_instance_name in self.databases:
|
||||
return self.databases[db_instance_name].get_tags()
|
||||
else:
|
||||
return []
|
||||
else:
|
||||
raise RDSClientError('InvalidParameterValue',
|
||||
'Invalid resource name: {}'.format(arn))
|
||||
|
||||
class OptionGroup(object):
|
||||
def __init__(self, name, engine_name, major_engine_version, description=None):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from moto.core.responses import BaseResponse
|
|||
from moto.ec2.models import ec2_backends
|
||||
from .models import rds2_backends
|
||||
import json
|
||||
import re
|
||||
|
||||
|
||||
class RDS2Response(BaseResponse):
|
||||
|
|
@ -73,8 +74,10 @@ class RDS2Response(BaseResponse):
|
|||
result = template.render(database=database)
|
||||
return result
|
||||
|
||||
# TODO: Update function to new method
|
||||
def create_dbinstance_read_replica(self):
|
||||
return self.create_db_instance_read_replica()
|
||||
|
||||
def create_db_instance_read_replica(self):
|
||||
db_kwargs = self._get_db_replica_kwargs()
|
||||
|
||||
database = self.backend.create_database_replica(db_kwargs)
|
||||
|
|
@ -84,7 +87,7 @@ class RDS2Response(BaseResponse):
|
|||
def describe_dbinstances(self):
|
||||
return self.describe_db_instances()
|
||||
|
||||
def describe_dbinstances(self):
|
||||
def describe_db_instances(self):
|
||||
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
||||
databases = self.backend.describe_databases(db_instance_identifier)
|
||||
template = self.response_template(DESCRIBE_DATABASES_TEMPLATE)
|
||||
|
|
@ -109,6 +112,21 @@ class RDS2Response(BaseResponse):
|
|||
template = self.response_template(DELETE_DATABASE_TEMPLATE)
|
||||
return template.render(database=database)
|
||||
|
||||
def reboot_dbinstance(self):
|
||||
return self.reboot_db_instance()
|
||||
|
||||
def reboot_db_instance(self):
|
||||
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
||||
database = self.backend.reboot_db_instance(db_instance_identifier)
|
||||
template = self.response_template(REBOOT_DATABASE_TEMPLATE)
|
||||
return template.render(database=database)
|
||||
|
||||
def list_tags_for_resource(self):
|
||||
arn = self._get_param('ResourceName')
|
||||
template = self.response_template(LIST_TAGS_FOR_RESOURCE_TEMPLATE)
|
||||
tags = self.backend.list_tags_for_resource(arn)
|
||||
return template.render(tags=tags)
|
||||
|
||||
# TODO: Update function to new method
|
||||
def create_dbsecurity_group(self):
|
||||
group_name = self._get_param('DBSecurityGroupName')
|
||||
|
|
@ -255,14 +273,24 @@ MODIFY_DATABASE_TEMPLATE = """{"ModifyDBInstanceResponse": {
|
|||
}
|
||||
}"""
|
||||
|
||||
# TODO: update delete DB TEMPLATE
|
||||
DELETE_DATABASE_TEMPLATE = """{
|
||||
"DeleteDBInstanceResponse": {
|
||||
"DeleteDBInstanceResult": {
|
||||
},
|
||||
"ResponseMetadata": { "RequestId": "523e3218-afc7-11c3-90f5-f90431260ab4" }
|
||||
REBOOT_DATABASE_TEMPLATE = """{"RebootDBInstanceResponse": {
|
||||
"RebootDBInstanceResult": {
|
||||
{{ database.to_json() }},
|
||||
"ResponseMetadata": {
|
||||
"RequestId": "d55711cb-a1ab-11e4-99cf-55e92d4bbada"
|
||||
}
|
||||
}
|
||||
}"""
|
||||
}}"""
|
||||
|
||||
# TODO: update delete DB TEMPLATE
|
||||
DELETE_DATABASE_TEMPLATE = """{ "DeleteDBInstanceResponse": {
|
||||
"DeleteDBInstanceResult": {
|
||||
{{ database.to_json() }},
|
||||
"ResponseMetadata": {
|
||||
"RequestId": "523e3218-afc7-11c3-90f5-f90431260ab4"
|
||||
}
|
||||
}
|
||||
}}"""
|
||||
|
||||
CREATE_SECURITY_GROUP_TEMPLATE = """<CreateDBSecurityGroupResponse xmlns="http://rds.amazonaws.com/doc/2014-09-01/">
|
||||
<CreateDBSecurityGroupResult>
|
||||
|
|
@ -379,3 +407,20 @@ MODIFY_OPTION_GROUP_TEMPLATE = \
|
|||
{{ option_group.to_json() }}
|
||||
}
|
||||
}"""
|
||||
|
||||
LIST_TAGS_FOR_RESOURCE_TEMPLATE = \
|
||||
"""{"ListTagsForResourceResponse":
|
||||
{"ListTagsForResourceResult":
|
||||
{"TagList": [
|
||||
{%- for tag in tags -%}
|
||||
{%- if loop.index != 1 -%},{%- endif -%}
|
||||
{%- for key in tag -%}
|
||||
{"Value": "{{ tag[key] }}", "Key": "{{ key }}"}
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
]},
|
||||
"ResponseMetadata": {
|
||||
"RequestId": "8c21ba39-a598-11e4-b688-194eaf8658fa"
|
||||
}
|
||||
}
|
||||
}"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue