Cleanup multi-region support for ELB, SQS, Cloudformation, EC2, Autoscaling.
This commit is contained in:
parent
b39861052b
commit
bd847bd941
16 changed files with 184 additions and 90 deletions
|
|
@ -1,3 +1,10 @@
|
|||
from __future__ import unicode_literals
|
||||
from .models import elb_backend
|
||||
mock_elb = elb_backend.decorator
|
||||
from .models import elb_backends, elb_backend # flake8: noqa
|
||||
from ..core.models import MockAWS
|
||||
|
||||
|
||||
def mock_elb(func=None):
|
||||
if func:
|
||||
return MockAWS(elb_backends)(func)
|
||||
else:
|
||||
return MockAWS(elb_backends)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto.ec2.elb
|
||||
from moto.core import BaseBackend
|
||||
|
||||
|
||||
|
|
@ -38,9 +40,10 @@ class FakeLoadBalancer(object):
|
|||
self.listeners.append(listener)
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json):
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
properties = cloudformation_json['Properties']
|
||||
|
||||
elb_backend = elb_backends[region_name]
|
||||
new_elb = elb_backend.create_load_balancer(
|
||||
name=properties.get('LoadBalancerName', resource_name),
|
||||
zones=properties.get('AvailabilityZones'),
|
||||
|
|
@ -148,4 +151,9 @@ class ELBBackend(BaseBackend):
|
|||
load_balancer.instance_ids = new_instance_ids
|
||||
return load_balancer
|
||||
|
||||
elb_backend = ELBBackend()
|
||||
|
||||
elb_backends = {}
|
||||
for region in boto.ec2.elb.regions():
|
||||
elb_backends[region.name] = ELBBackend()
|
||||
|
||||
elb_backend = elb_backends['us-east-1']
|
||||
|
|
|
|||
|
|
@ -2,11 +2,15 @@ from __future__ import unicode_literals
|
|||
from jinja2 import Template
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
from .models import elb_backend
|
||||
from .models import elb_backends
|
||||
|
||||
|
||||
class ELBResponse(BaseResponse):
|
||||
|
||||
@property
|
||||
def elb_backend(self):
|
||||
return elb_backends[self.region]
|
||||
|
||||
def create_load_balancer(self):
|
||||
"""
|
||||
u'Scheme': [u'internet-facing'],
|
||||
|
|
@ -26,7 +30,7 @@ class ELBResponse(BaseResponse):
|
|||
ports.append([protocol, lb_port, instance_port, ssl_certificate_id])
|
||||
port_index += 1
|
||||
|
||||
elb_backend.create_load_balancer(
|
||||
self.elb_backend.create_load_balancer(
|
||||
name=load_balancer_name,
|
||||
zones=availability_zones,
|
||||
ports=ports,
|
||||
|
|
@ -49,14 +53,14 @@ class ELBResponse(BaseResponse):
|
|||
ports.append([protocol, lb_port, instance_port, ssl_certificate_id])
|
||||
port_index += 1
|
||||
|
||||
elb_backend.create_load_balancer_listeners(name=load_balancer_name, ports=ports)
|
||||
self.elb_backend.create_load_balancer_listeners(name=load_balancer_name, ports=ports)
|
||||
|
||||
template = Template(CREATE_LOAD_BALANCER_LISTENERS_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
def describe_load_balancers(self):
|
||||
names = [value[0] for key, value in self.querystring.items() if "LoadBalancerNames.member" in key]
|
||||
load_balancers = elb_backend.describe_load_balancers(names)
|
||||
load_balancers = self.elb_backend.describe_load_balancers(names)
|
||||
template = Template(DESCRIBE_LOAD_BALANCERS_TEMPLATE)
|
||||
return template.render(load_balancers=load_balancers)
|
||||
|
||||
|
|
@ -73,18 +77,18 @@ class ELBResponse(BaseResponse):
|
|||
port_index += 1
|
||||
ports.append(int(port))
|
||||
|
||||
elb_backend.delete_load_balancer_listeners(load_balancer_name, ports)
|
||||
self.elb_backend.delete_load_balancer_listeners(load_balancer_name, ports)
|
||||
template = Template(DELETE_LOAD_BALANCER_LISTENERS)
|
||||
return template.render()
|
||||
|
||||
def delete_load_balancer(self):
|
||||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
elb_backend.delete_load_balancer(load_balancer_name)
|
||||
self.elb_backend.delete_load_balancer(load_balancer_name)
|
||||
template = Template(DELETE_LOAD_BALANCER_TEMPLATE)
|
||||
return template.render()
|
||||
|
||||
def configure_health_check(self):
|
||||
check = elb_backend.configure_health_check(
|
||||
check = self.elb_backend.configure_health_check(
|
||||
load_balancer_name=self.querystring.get('LoadBalancerName')[0],
|
||||
timeout=self.querystring.get('HealthCheck.Timeout')[0],
|
||||
healthy_threshold=self.querystring.get('HealthCheck.HealthyThreshold')[0],
|
||||
|
|
@ -99,7 +103,7 @@ class ELBResponse(BaseResponse):
|
|||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
instance_ids = [value[0] for key, value in self.querystring.items() if "Instances.member" in key]
|
||||
template = Template(REGISTER_INSTANCES_TEMPLATE)
|
||||
load_balancer = elb_backend.register_instances(load_balancer_name, instance_ids)
|
||||
load_balancer = self.elb_backend.register_instances(load_balancer_name, instance_ids)
|
||||
return template.render(load_balancer=load_balancer)
|
||||
|
||||
def set_load_balancer_listener_sslcertificate(self):
|
||||
|
|
@ -107,7 +111,7 @@ class ELBResponse(BaseResponse):
|
|||
ssl_certificate_id = self.querystring['SSLCertificateId'][0]
|
||||
lb_port = self.querystring['LoadBalancerPort'][0]
|
||||
|
||||
elb_backend.set_load_balancer_listener_sslcertificate(load_balancer_name, lb_port, ssl_certificate_id)
|
||||
self.elb_backend.set_load_balancer_listener_sslcertificate(load_balancer_name, lb_port, ssl_certificate_id)
|
||||
|
||||
template = Template(SET_LOAD_BALANCER_SSL_CERTIFICATE)
|
||||
return template.render()
|
||||
|
|
@ -116,7 +120,7 @@ class ELBResponse(BaseResponse):
|
|||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
instance_ids = [value[0] for key, value in self.querystring.items() if "Instances.member" in key]
|
||||
template = Template(DEREGISTER_INSTANCES_TEMPLATE)
|
||||
load_balancer = elb_backend.deregister_instances(load_balancer_name, instance_ids)
|
||||
load_balancer = self.elb_backend.deregister_instances(load_balancer_name, instance_ids)
|
||||
return template.render(load_balancer=load_balancer)
|
||||
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue