Lints.
This commit is contained in:
parent
1433f28846
commit
f37bad0e00
260 changed files with 6363 additions and 3766 deletions
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from .models import rds_backends
|
||||
from ..core.models import MockAWS, base_decorator, HttprettyMockAWS, deprecated_base_decorator
|
||||
from ..core.models import base_decorator, deprecated_base_decorator
|
||||
|
||||
rds_backend = rds_backends['us-east-1']
|
||||
mock_rds = base_decorator(rds_backends)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from werkzeug.exceptions import BadRequest
|
|||
|
||||
|
||||
class RDSClientError(BadRequest):
|
||||
|
||||
def __init__(self, code, message):
|
||||
super(RDSClientError, self).__init__()
|
||||
self.description = json.dumps({
|
||||
|
|
@ -18,6 +19,7 @@ class RDSClientError(BadRequest):
|
|||
|
||||
|
||||
class DBInstanceNotFoundError(RDSClientError):
|
||||
|
||||
def __init__(self, database_identifier):
|
||||
super(DBInstanceNotFoundError, self).__init__(
|
||||
'DBInstanceNotFound',
|
||||
|
|
@ -25,6 +27,7 @@ class DBInstanceNotFoundError(RDSClientError):
|
|||
|
||||
|
||||
class DBSecurityGroupNotFoundError(RDSClientError):
|
||||
|
||||
def __init__(self, security_group_name):
|
||||
super(DBSecurityGroupNotFoundError, self).__init__(
|
||||
'DBSecurityGroupNotFound',
|
||||
|
|
@ -32,6 +35,7 @@ class DBSecurityGroupNotFoundError(RDSClientError):
|
|||
|
||||
|
||||
class DBSubnetGroupNotFoundError(RDSClientError):
|
||||
|
||||
def __init__(self, subnet_group_name):
|
||||
super(DBSubnetGroupNotFoundError, self).__init__(
|
||||
'DBSubnetGroupNotFound',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
|
||||
import boto.rds
|
||||
|
|
@ -11,10 +10,10 @@ from moto.core import BaseBackend
|
|||
from moto.core.utils import get_random_hex
|
||||
from moto.ec2.models import ec2_backends
|
||||
from moto.rds2.models import rds2_backends
|
||||
from .exceptions import DBInstanceNotFoundError, DBSecurityGroupNotFoundError, DBSubnetGroupNotFoundError
|
||||
|
||||
|
||||
class Database(object):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.status = "available"
|
||||
|
||||
|
|
@ -35,7 +34,8 @@ class Database(object):
|
|||
self.storage_type = kwargs.get("storage_type")
|
||||
self.master_username = kwargs.get('master_username')
|
||||
self.master_password = kwargs.get('master_password')
|
||||
self.auto_minor_version_upgrade = kwargs.get('auto_minor_version_upgrade')
|
||||
self.auto_minor_version_upgrade = kwargs.get(
|
||||
'auto_minor_version_upgrade')
|
||||
if self.auto_minor_version_upgrade is None:
|
||||
self.auto_minor_version_upgrade = True
|
||||
self.allocated_storage = kwargs.get('allocated_storage')
|
||||
|
|
@ -57,7 +57,8 @@ class Database(object):
|
|||
self.db_subnet_group_name = kwargs.get("db_subnet_group_name")
|
||||
self.instance_create_time = str(datetime.datetime.utcnow())
|
||||
if self.db_subnet_group_name:
|
||||
self.db_subnet_group = rds_backends[self.region].describe_subnet_groups(self.db_subnet_group_name)[0]
|
||||
self.db_subnet_group = rds_backends[
|
||||
self.region].describe_subnet_groups(self.db_subnet_group_name)[0]
|
||||
else:
|
||||
self.db_subnet_group = []
|
||||
|
||||
|
|
@ -239,6 +240,7 @@ class Database(object):
|
|||
|
||||
|
||||
class SecurityGroup(object):
|
||||
|
||||
def __init__(self, group_name, description):
|
||||
self.group_name = group_name
|
||||
self.description = description
|
||||
|
|
@ -284,7 +286,8 @@ class SecurityGroup(object):
|
|||
properties = cloudformation_json['Properties']
|
||||
group_name = resource_name.lower() + get_random_hex(12)
|
||||
description = properties['GroupDescription']
|
||||
security_group_ingress_rules = properties.get('DBSecurityGroupIngress', [])
|
||||
security_group_ingress_rules = properties.get(
|
||||
'DBSecurityGroupIngress', [])
|
||||
tags = properties.get('Tags')
|
||||
|
||||
ec2_backend = ec2_backends[region_name]
|
||||
|
|
@ -300,10 +303,12 @@ class SecurityGroup(object):
|
|||
if ingress_type == "CIDRIP":
|
||||
security_group.authorize_cidr(ingress_value)
|
||||
elif ingress_type == "EC2SecurityGroupName":
|
||||
subnet = ec2_backend.get_security_group_from_name(ingress_value)
|
||||
subnet = ec2_backend.get_security_group_from_name(
|
||||
ingress_value)
|
||||
security_group.authorize_security_group(subnet)
|
||||
elif ingress_type == "EC2SecurityGroupId":
|
||||
subnet = ec2_backend.get_security_group_from_id(ingress_value)
|
||||
subnet = ec2_backend.get_security_group_from_id(
|
||||
ingress_value)
|
||||
security_group.authorize_security_group(subnet)
|
||||
return security_group
|
||||
|
||||
|
|
@ -313,6 +318,7 @@ class SecurityGroup(object):
|
|||
|
||||
|
||||
class SubnetGroup(object):
|
||||
|
||||
def __init__(self, subnet_name, description, subnets):
|
||||
self.subnet_name = subnet_name
|
||||
self.description = description
|
||||
|
|
@ -352,7 +358,8 @@ class SubnetGroup(object):
|
|||
tags = properties.get('Tags')
|
||||
|
||||
ec2_backend = ec2_backends[region_name]
|
||||
subnets = [ec2_backend.get_subnet(subnet_id) for subnet_id in subnet_ids]
|
||||
subnets = [ec2_backend.get_subnet(subnet_id)
|
||||
for subnet_id in subnet_ids]
|
||||
rds_backend = rds_backends[region_name]
|
||||
subnet_group = rds_backend.create_subnet_group(
|
||||
subnet_name,
|
||||
|
|
@ -385,4 +392,6 @@ class RDSBackend(BaseBackend):
|
|||
def rds2_backend(self):
|
||||
return rds2_backends[self.region]
|
||||
|
||||
rds_backends = dict((region.name, RDSBackend(region.name)) for region in boto.rds.regions())
|
||||
|
||||
rds_backends = dict((region.name, RDSBackend(region.name))
|
||||
for region in boto.rds.regions())
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class RDSResponse(BaseResponse):
|
|||
# VpcSecurityGroupIds.member.N
|
||||
"tags": list(),
|
||||
}
|
||||
args['tags'] = self.unpack_complex_list_params('Tags.Tag', ('Key', 'Value'))
|
||||
args['tags'] = self.unpack_complex_list_params(
|
||||
'Tags.Tag', ('Key', 'Value'))
|
||||
return args
|
||||
|
||||
def _get_db_replica_kwargs(self):
|
||||
|
|
@ -65,7 +66,8 @@ class RDSResponse(BaseResponse):
|
|||
while self._get_param('{0}.{1}.{2}'.format(label, count, names[0])):
|
||||
param = dict()
|
||||
for i in range(len(names)):
|
||||
param[names[i]] = self._get_param('{0}.{1}.{2}'.format(label, count, names[i]))
|
||||
param[names[i]] = self._get_param(
|
||||
'{0}.{1}.{2}'.format(label, count, names[i]))
|
||||
unpacked_list.append(param)
|
||||
count += 1
|
||||
return unpacked_list
|
||||
|
|
@ -93,7 +95,8 @@ class RDSResponse(BaseResponse):
|
|||
def modify_dbinstance(self):
|
||||
db_instance_identifier = self._get_param('DBInstanceIdentifier')
|
||||
db_kwargs = self._get_db_kwargs()
|
||||
database = self.backend.modify_database(db_instance_identifier, db_kwargs)
|
||||
database = self.backend.modify_database(
|
||||
db_instance_identifier, db_kwargs)
|
||||
template = self.response_template(MODIFY_DATABASE_TEMPLATE)
|
||||
return template.render(database=database)
|
||||
|
||||
|
|
@ -107,26 +110,30 @@ class RDSResponse(BaseResponse):
|
|||
group_name = self._get_param('DBSecurityGroupName')
|
||||
description = self._get_param('DBSecurityGroupDescription')
|
||||
tags = self.unpack_complex_list_params('Tags.Tag', ('Key', 'Value'))
|
||||
security_group = self.backend.create_security_group(group_name, description, tags)
|
||||
security_group = self.backend.create_security_group(
|
||||
group_name, description, tags)
|
||||
template = self.response_template(CREATE_SECURITY_GROUP_TEMPLATE)
|
||||
return template.render(security_group=security_group)
|
||||
|
||||
def describe_dbsecurity_groups(self):
|
||||
security_group_name = self._get_param('DBSecurityGroupName')
|
||||
security_groups = self.backend.describe_security_groups(security_group_name)
|
||||
security_groups = self.backend.describe_security_groups(
|
||||
security_group_name)
|
||||
template = self.response_template(DESCRIBE_SECURITY_GROUPS_TEMPLATE)
|
||||
return template.render(security_groups=security_groups)
|
||||
|
||||
def delete_dbsecurity_group(self):
|
||||
security_group_name = self._get_param('DBSecurityGroupName')
|
||||
security_group = self.backend.delete_security_group(security_group_name)
|
||||
security_group = self.backend.delete_security_group(
|
||||
security_group_name)
|
||||
template = self.response_template(DELETE_SECURITY_GROUP_TEMPLATE)
|
||||
return template.render(security_group=security_group)
|
||||
|
||||
def authorize_dbsecurity_group_ingress(self):
|
||||
security_group_name = self._get_param('DBSecurityGroupName')
|
||||
cidr_ip = self._get_param('CIDRIP')
|
||||
security_group = self.backend.authorize_security_group(security_group_name, cidr_ip)
|
||||
security_group = self.backend.authorize_security_group(
|
||||
security_group_name, cidr_ip)
|
||||
template = self.response_template(AUTHORIZE_SECURITY_GROUP_TEMPLATE)
|
||||
return template.render(security_group=security_group)
|
||||
|
||||
|
|
@ -134,9 +141,11 @@ class RDSResponse(BaseResponse):
|
|||
subnet_name = self._get_param('DBSubnetGroupName')
|
||||
description = self._get_param('DBSubnetGroupDescription')
|
||||
subnet_ids = self._get_multi_param('SubnetIds.member')
|
||||
subnets = [ec2_backends[self.region].get_subnet(subnet_id) for subnet_id in subnet_ids]
|
||||
subnets = [ec2_backends[self.region].get_subnet(
|
||||
subnet_id) for subnet_id in subnet_ids]
|
||||
tags = self.unpack_complex_list_params('Tags.Tag', ('Key', 'Value'))
|
||||
subnet_group = self.backend.create_subnet_group(subnet_name, description, subnets, tags)
|
||||
subnet_group = self.backend.create_subnet_group(
|
||||
subnet_name, description, subnets, tags)
|
||||
template = self.response_template(CREATE_SUBNET_GROUP_TEMPLATE)
|
||||
return template.render(subnet_group=subnet_group)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue