Fix merge conflicts and add EC2 Instance delete. Closes #576.
This commit is contained in:
parent
0b24c6be57
commit
a600deb96a
12 changed files with 461 additions and 50 deletions
|
|
@ -64,20 +64,21 @@ class FakeLoadBalancer(object):
|
|||
self.subnets = subnets or []
|
||||
self.vpc_id = vpc_id or 'vpc-56e10e3d'
|
||||
self.tags = {}
|
||||
self.dns_name = "tests.us-east-1.elb.amazonaws.com"
|
||||
|
||||
for port in ports:
|
||||
listener = FakeListener(
|
||||
protocol=port['protocol'],
|
||||
load_balancer_port=port['load_balancer_port'],
|
||||
instance_port=port['instance_port'],
|
||||
ssl_certificate_id=port.get('sslcertificate_id'),
|
||||
protocol=(port.get('protocol') or port['Protocol']),
|
||||
load_balancer_port=(port.get('load_balancer_port') or port['LoadBalancerPort']),
|
||||
instance_port=(port.get('instance_port') or port['InstancePort']),
|
||||
ssl_certificate_id=port.get('sslcertificate_id', port.get('SSLCertificateId')),
|
||||
)
|
||||
self.listeners.append(listener)
|
||||
|
||||
# it is unclear per the AWS documentation as to when or how backend
|
||||
# information gets set, so let's guess and set it here *shrug*
|
||||
backend = FakeBackend(
|
||||
instance_port=port['instance_port'],
|
||||
instance_port=(port.get('instance_port') or port['InstancePort']),
|
||||
)
|
||||
self.backends.append(backend)
|
||||
|
||||
|
|
@ -88,15 +89,41 @@ class FakeLoadBalancer(object):
|
|||
elb_backend = elb_backends[region_name]
|
||||
new_elb = elb_backend.create_load_balancer(
|
||||
name=properties.get('LoadBalancerName', resource_name),
|
||||
zones=properties.get('AvailabilityZones'),
|
||||
ports=[],
|
||||
zones=properties.get('AvailabilityZones', []),
|
||||
ports=properties['Listeners'],
|
||||
scheme=properties.get('Scheme', 'internet-facing'),
|
||||
)
|
||||
|
||||
instance_ids = cloudformation_json.get('Instances', [])
|
||||
instance_ids = properties.get('Instances', [])
|
||||
for instance_id in instance_ids:
|
||||
elb_backend.register_instances(new_elb.name, [instance_id])
|
||||
|
||||
health_check = properties.get('HealthCheck')
|
||||
if health_check:
|
||||
elb_backend.configure_health_check(
|
||||
load_balancer_name=new_elb.name,
|
||||
timeout=health_check['Timeout'],
|
||||
healthy_threshold=health_check['HealthyThreshold'],
|
||||
unhealthy_threshold=health_check['UnhealthyThreshold'],
|
||||
interval=health_check['Interval'],
|
||||
target=health_check['Target'],
|
||||
)
|
||||
|
||||
return new_elb
|
||||
|
||||
@classmethod
|
||||
def update_from_cloudformation_json(cls, original_resource, new_resource_name, cloudformation_json, region_name):
|
||||
cls.delete_from_cloudformation_json(original_resource.name, cloudformation_json, region_name)
|
||||
return cls.create_from_cloudformation_json(new_resource_name, cloudformation_json, region_name)
|
||||
|
||||
@classmethod
|
||||
def delete_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
elb_backend = elb_backends[region_name]
|
||||
try:
|
||||
elb_backend.delete_load_balancer(resource_name)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def physical_resource_id(self):
|
||||
return self.name
|
||||
|
|
@ -108,7 +135,7 @@ class FakeLoadBalancer(object):
|
|||
elif attribute_name == 'CanonicalHostedZoneNameID':
|
||||
raise NotImplementedError('"Fn::GetAtt" : [ "{0}" , "CanonicalHostedZoneNameID" ]"')
|
||||
elif attribute_name == 'DNSName':
|
||||
raise NotImplementedError('"Fn::GetAtt" : [ "{0}" , "DNSName" ]"')
|
||||
return self.dns_name
|
||||
elif attribute_name == 'SourceSecurityGroup.GroupName':
|
||||
raise NotImplementedError('"Fn::GetAtt" : [ "{0}" , "SourceSecurityGroup.GroupName" ]"')
|
||||
elif attribute_name == 'SourceSecurityGroup.OwnerAlias':
|
||||
|
|
@ -149,6 +176,10 @@ class FakeLoadBalancer(object):
|
|||
if key in self.tags:
|
||||
del self.tags[key]
|
||||
|
||||
def delete(self, region):
|
||||
''' Not exposed as part of the ELB API - used for CloudFormation. '''
|
||||
elb_backends[region].delete_load_balancer(self.name)
|
||||
|
||||
|
||||
class ELBBackend(BaseBackend):
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,7 @@ from boto.ec2.elb.policies import (
|
|||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import elb_backends
|
||||
from .exceptions import DuplicateTagKeysError, LoadBalancerNotFoundError, \
|
||||
TooManyTagsError
|
||||
from .exceptions import DuplicateTagKeysError, LoadBalancerNotFoundError
|
||||
|
||||
|
||||
class ELBResponse(BaseResponse):
|
||||
|
|
@ -29,16 +28,16 @@ class ELBResponse(BaseResponse):
|
|||
scheme = self._get_param('Scheme')
|
||||
subnets = self._get_multi_param("Subnets.member")
|
||||
|
||||
elb = self.elb_backend.create_load_balancer(
|
||||
load_balancer = self.elb_backend.create_load_balancer(
|
||||
name=load_balancer_name,
|
||||
zones=availability_zones,
|
||||
ports=ports,
|
||||
scheme=scheme,
|
||||
subnets=subnets,
|
||||
)
|
||||
self._add_tags(elb)
|
||||
self._add_tags(load_balancer)
|
||||
template = self.response_template(CREATE_LOAD_BALANCER_TEMPLATE)
|
||||
return template.render()
|
||||
return template.render(load_balancer=load_balancer)
|
||||
|
||||
def create_load_balancer_listeners(self):
|
||||
load_balancer_name = self._get_param('LoadBalancerName')
|
||||
|
|
@ -244,7 +243,7 @@ class ELBResponse(BaseResponse):
|
|||
load_balancer_name = self._get_param('LoadBalancerNames.member.{0}'.format(number))
|
||||
elb = self.elb_backend.get_load_balancer(load_balancer_name)
|
||||
if not elb:
|
||||
raise LoadBalancerNotFound(load_balancer_name)
|
||||
raise LoadBalancerNotFoundError(load_balancer_name)
|
||||
|
||||
key = 'Tag.member.{0}.Key'.format(number)
|
||||
for t_key, t_val in self.querystring.items():
|
||||
|
|
@ -263,7 +262,7 @@ class ELBResponse(BaseResponse):
|
|||
load_balancer_name = self._get_param('LoadBalancerNames.member.{0}'.format(number))
|
||||
elb = self.elb_backend.get_load_balancer(load_balancer_name)
|
||||
if not elb:
|
||||
raise LoadBalancerNotFound(load_balancer_name)
|
||||
raise LoadBalancerNotFoundError(load_balancer_name)
|
||||
elbs.append(elb)
|
||||
|
||||
template = self.response_template(DESCRIBE_TAGS_TEMPLATE)
|
||||
|
|
@ -334,7 +333,7 @@ DESCRIBE_TAGS_TEMPLATE = """<DescribeTagsResponse xmlns="http://elasticloadbalan
|
|||
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<CreateLoadBalancerResult>
|
||||
<DNSName>tests.us-east-1.elb.amazonaws.com</DNSName>
|
||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||
</CreateLoadBalancerResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||
|
|
@ -442,7 +441,7 @@ DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http
|
|||
<CanonicalHostedZoneName>tests.us-east-1.elb.amazonaws.com</CanonicalHostedZoneName>
|
||||
<CanonicalHostedZoneNameID>Z3ZONEID</CanonicalHostedZoneNameID>
|
||||
<Scheme>{{ load_balancer.scheme }}</Scheme>
|
||||
<DNSName>tests.us-east-1.elb.amazonaws.com</DNSName>
|
||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||
<BackendServerDescriptions>
|
||||
{% for backend in load_balancer.backends %}
|
||||
<member>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue