Merge branch 'mrucci-elb-describe-instances-health'
This commit is contained in:
commit
fcf5cdb960
@ -177,6 +177,14 @@ class ELBResponse(BaseResponse):
|
||||
template = self.response_template(MODIFY_ATTRIBUTES_TEMPLATE)
|
||||
return template.render(attributes=load_balancer.attributes)
|
||||
|
||||
def describe_instance_health(self):
|
||||
load_balancer_name = self.querystring.get('LoadBalancerName')[0]
|
||||
instance_ids = [value[0] for key, value in self.querystring.items() if "Instances.member" in key]
|
||||
if len(instance_ids) == 0:
|
||||
instance_ids = self.elb_backend.describe_load_balancers(load_balancer_name)[0].instance_ids
|
||||
template = self.response_template(DESCRIBE_INSTANCE_HEALTH_TEMPLATE)
|
||||
return template.render(instance_ids=instance_ids)
|
||||
|
||||
|
||||
CREATE_LOAD_BALANCER_TEMPLATE = """<CreateLoadBalancerResult xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DNSName>tests.us-east-1.elb.amazonaws.com</DNSName>
|
||||
@ -364,7 +372,7 @@ MODIFY_ATTRIBUTES_TEMPLATE = """<ModifyLoadBalancerAttributesResponse xmlns="htt
|
||||
{% if attributes.connection_draining.enabled %}
|
||||
<Timeout>{{ attributes.connection_draining.timeout }}</Timeout>
|
||||
{% endif %}
|
||||
</ConnectionDraining>
|
||||
</ConnectionDraining>
|
||||
</LoadBalancerAttributes>
|
||||
</ModifyLoadBalancerAttributesResult>
|
||||
<ResponseMetadata>
|
||||
@ -373,3 +381,20 @@ MODIFY_ATTRIBUTES_TEMPLATE = """<ModifyLoadBalancerAttributesResponse xmlns="htt
|
||||
</ModifyLoadBalancerAttributesResponse>
|
||||
"""
|
||||
|
||||
DESCRIBE_INSTANCE_HEALTH_TEMPLATE = """<DescribeInstanceHealthResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
|
||||
<DescribeInstanceHealthResult>
|
||||
<InstanceStates>
|
||||
{% for instance_id in instance_ids %}
|
||||
<member>
|
||||
<Description>N/A</Description>
|
||||
<InstanceId>{{ instance_id }}</InstanceId>
|
||||
<State>InService</State>
|
||||
<ReasonCode>N/A</ReasonCode>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</InstanceStates>
|
||||
</DescribeInstanceHealthResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</DescribeInstanceHealthResponse>"""
|
||||
|
@ -199,6 +199,7 @@ def test_deregister_instances():
|
||||
balancer.instances.should.have.length_of(1)
|
||||
balancer.instances[0].id.should.equal(instance_id2)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_default_attributes():
|
||||
conn = boto.connect_elb()
|
||||
@ -226,6 +227,7 @@ def test_cross_zone_load_balancing_attribute():
|
||||
attributes = lb.get_attributes(force=True)
|
||||
attributes.cross_zone_load_balancing.enabled.should.be.false
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_connection_draining_attribute():
|
||||
conn = boto.connect_elb()
|
||||
@ -251,6 +253,7 @@ def test_connection_draining_attribute():
|
||||
attributes = lb.get_attributes(force=True)
|
||||
attributes.connection_draining.enabled.should.be.false
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_access_log_attribute():
|
||||
conn = boto.connect_elb()
|
||||
@ -275,6 +278,7 @@ def test_access_log_attribute():
|
||||
attributes = lb.get_attributes(force=True)
|
||||
attributes.access_log.enabled.should.be.false
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_connection_settings_attribute():
|
||||
conn = boto.connect_elb()
|
||||
@ -294,3 +298,31 @@ def test_connection_settings_attribute():
|
||||
attributes.connecting_settings.idle_timeout.should.equal(60)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_elb
|
||||
def test_describe_instance_health():
|
||||
ec2_conn = boto.connect_ec2()
|
||||
reservation = ec2_conn.run_instances('ami-1234abcd', 2)
|
||||
instance_id1 = reservation.instances[0].id
|
||||
instance_id2 = reservation.instances[1].id
|
||||
|
||||
conn = boto.connect_elb()
|
||||
zones = ['us-east-1a', 'us-east-1b']
|
||||
ports = [(80, 8080, 'http'), (443, 8443, 'tcp')]
|
||||
lb = conn.create_load_balancer('my-lb', zones, ports)
|
||||
|
||||
instances_health = conn.describe_instance_health('my-lb')
|
||||
instances_health.should.be.empty
|
||||
|
||||
lb.register_instances([instance_id1, instance_id2])
|
||||
|
||||
instances_health = conn.describe_instance_health('my-lb')
|
||||
instances_health.should.have.length_of(2)
|
||||
for instance_health in instances_health:
|
||||
instance_health.instance_id.should.be.within([instance_id1, instance_id2])
|
||||
instance_health.state.should.equal('InService')
|
||||
|
||||
instances_health = conn.describe_instance_health('my-lb', [instance_id1])
|
||||
instances_health.should.have.length_of(1)
|
||||
instances_health[0].instance_id.should.equal(instance_id1)
|
||||
instances_health[0].state.should.equal('InService')
|
||||
|
Loading…
Reference in New Issue
Block a user