Merge pull request #487 from a1exsh/bugfix/include-load-balancer-name-in-describe-tags-response

Fix ELB.describe_tags with multiple LoadBalancerNames.
This commit is contained in:
Steve Pulec 2016-01-17 16:34:20 -05:00
commit fe090d7bb5
2 changed files with 28 additions and 2 deletions

View File

@ -277,6 +277,7 @@ class ELBResponse(BaseResponse):
return template.render() return template.render()
def describe_tags(self): def describe_tags(self):
elbs = []
for key, value in self.querystring.items(): for key, value in self.querystring.items():
if "LoadBalancerNames.member" in key: if "LoadBalancerNames.member" in key:
number = key.split('.')[2] number = key.split('.')[2]
@ -284,9 +285,10 @@ class ELBResponse(BaseResponse):
elb = self.elb_backend.get_load_balancer(load_balancer_name) elb = self.elb_backend.get_load_balancer(load_balancer_name)
if not elb: if not elb:
raise LoadBalancerNotFound(load_balancer_name) raise LoadBalancerNotFound(load_balancer_name)
elbs.append(elb)
template = self.response_template(DESCRIBE_TAGS_TEMPLATE) template = self.response_template(DESCRIBE_TAGS_TEMPLATE)
return template.render(tags=elb.tags) return template.render(load_balancers=elbs)
ADD_TAGS_TEMPLATE = """<AddTagsResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/"> ADD_TAGS_TEMPLATE = """<AddTagsResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<AddTagsResult/> <AddTagsResult/>
@ -305,9 +307,11 @@ REMOVE_TAGS_TEMPLATE = """<RemoveTagsResponse xmlns="http://elasticloadbalancing
DESCRIBE_TAGS_TEMPLATE = """<DescribeTagsResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/"> DESCRIBE_TAGS_TEMPLATE = """<DescribeTagsResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
<DescribeTagsResult> <DescribeTagsResult>
<TagDescriptions> <TagDescriptions>
{% for elb in load_balancers %}
<member> <member>
<LoadBalancerName>{{ elb.name }}</LoadBalancerName>
<Tags> <Tags>
{% for key, value in tags.items() %} {% for key, value in elb.tags.items() %}
<member> <member>
<Value>{{ value }}</Value> <Value>{{ value }}</Value>
<Key>{{ key }}</Key> <Key>{{ key }}</Key>
@ -315,6 +319,7 @@ DESCRIBE_TAGS_TEMPLATE = """<DescribeTagsResponse xmlns="http://elasticloadbalan
{% endfor %} {% endfor %}
</Tags> </Tags>
</member> </member>
{% endfor %}
</TagDescriptions> </TagDescriptions>
</DescribeTagsResult> </DescribeTagsResult>
<ResponseMetadata> <ResponseMetadata>

View File

@ -698,3 +698,24 @@ def test_add_remove_tags():
tags.should.have.key('i').which.should.equal('b') tags.should.have.key('i').which.should.equal('b')
tags.should.have.key('j').which.should.equal('c') tags.should.have.key('j').which.should.equal('c')
client.create_load_balancer(
LoadBalancerName='other-lb',
Listeners=[{'Protocol':'tcp', 'LoadBalancerPort':433, 'InstancePort':8433}],
AvailabilityZones=['us-east-1a', 'us-east-1b']
)
client.add_tags(LoadBalancerNames=['other-lb'],
Tags=[{
'Key': 'other',
'Value': 'something'
}])
lb_tags = dict([(l['LoadBalancerName'], dict([(d['Key'], d['Value']) for d in l['Tags']]))
for l in client.describe_tags(LoadBalancerNames=['my-lb', 'other-lb'])['TagDescriptions']])
lb_tags.should.have.key('my-lb')
lb_tags.should.have.key('other-lb')
lb_tags['my-lb'].shouldnt.have.key('other')
lb_tags['other-lb'].should.have.key('other').which.should.equal('something')