Allow ELB policies to be set via Cloudformation. (#809)
Also more closely mirror AWS by not returning ELB BackendServerDescriptions that don't have policies. Signed-off-by: Michael Nussbaum <michael.nussbaum@getbraintree.com>
This commit is contained in:
parent
e1260bca06
commit
51129f6ef3
@ -8,7 +8,10 @@ from boto.ec2.elb.attributes import (
|
|||||||
AccessLogAttribute,
|
AccessLogAttribute,
|
||||||
CrossZoneLoadBalancingAttribute,
|
CrossZoneLoadBalancingAttribute,
|
||||||
)
|
)
|
||||||
from boto.ec2.elb.policies import Policies
|
from boto.ec2.elb.policies import (
|
||||||
|
Policies,
|
||||||
|
OtherPolicy,
|
||||||
|
)
|
||||||
from moto.core import BaseBackend
|
from moto.core import BaseBackend
|
||||||
from moto.ec2.models import ec2_backends
|
from moto.ec2.models import ec2_backends
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
@ -104,6 +107,21 @@ class FakeLoadBalancer(object):
|
|||||||
for instance_id in instance_ids:
|
for instance_id in instance_ids:
|
||||||
elb_backend.register_instances(new_elb.name, [instance_id])
|
elb_backend.register_instances(new_elb.name, [instance_id])
|
||||||
|
|
||||||
|
policies = properties.get('Policies', [])
|
||||||
|
port_policies = {}
|
||||||
|
for policy in policies:
|
||||||
|
policy_name = policy["PolicyName"]
|
||||||
|
other_policy = OtherPolicy()
|
||||||
|
other_policy.policy_name = policy_name
|
||||||
|
elb_backend.create_lb_other_policy(new_elb.name, other_policy)
|
||||||
|
for port in policy.get("InstancePorts", []):
|
||||||
|
policies_for_port = port_policies.get(port, set())
|
||||||
|
policies_for_port.add(policy_name)
|
||||||
|
port_policies[port] = policies_for_port
|
||||||
|
|
||||||
|
for port, policies in port_policies.items():
|
||||||
|
elb_backend.set_load_balancer_policies_of_backend_server(new_elb.name, port, list(policies))
|
||||||
|
|
||||||
health_check = properties.get('HealthCheck')
|
health_check = properties.get('HealthCheck')
|
||||||
if health_check:
|
if health_check:
|
||||||
elb_backend.configure_health_check(
|
elb_backend.configure_health_check(
|
||||||
@ -307,7 +325,9 @@ class ELBBackend(BaseBackend):
|
|||||||
|
|
||||||
def create_lb_other_policy(self, load_balancer_name, other_policy):
|
def create_lb_other_policy(self, load_balancer_name, other_policy):
|
||||||
load_balancer = self.get_load_balancer(load_balancer_name)
|
load_balancer = self.get_load_balancer(load_balancer_name)
|
||||||
|
if other_policy.policy_name not in [p.policy_name for p in load_balancer.policies.other_policies]:
|
||||||
load_balancer.policies.other_policies.append(other_policy)
|
load_balancer.policies.other_policies.append(other_policy)
|
||||||
|
|
||||||
return load_balancer
|
return load_balancer
|
||||||
|
|
||||||
def create_app_cookie_stickiness_policy(self, load_balancer_name, policy):
|
def create_app_cookie_stickiness_policy(self, load_balancer_name, policy):
|
||||||
|
@ -445,18 +445,16 @@ DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http
|
|||||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||||
<BackendServerDescriptions>
|
<BackendServerDescriptions>
|
||||||
{% for backend in load_balancer.backends %}
|
{% for backend in load_balancer.backends %}
|
||||||
<member>
|
|
||||||
{% if backend.instance_port %}
|
|
||||||
<InstancePort>{{ backend.instance_port }}</InstancePort>
|
|
||||||
{% endif %}
|
|
||||||
{% if backend.policy_names %}
|
{% if backend.policy_names %}
|
||||||
|
<member>
|
||||||
|
<InstancePort>{{ backend.instance_port }}</InstancePort>
|
||||||
<PolicyNames>
|
<PolicyNames>
|
||||||
{% for policy in backend.policy_names %}
|
{% for policy in backend.policy_names %}
|
||||||
<member>{{ policy }}</member>
|
<member>{{ policy }}</member>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</PolicyNames>
|
</PolicyNames>
|
||||||
{% endif %}
|
|
||||||
</member>
|
</member>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</BackendServerDescriptions>
|
</BackendServerDescriptions>
|
||||||
<Subnets>
|
<Subnets>
|
||||||
|
Loading…
Reference in New Issue
Block a user