Skip to content

Commit

Permalink
fix: returns all LBs if names is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
christophemorio authored and tremble committed Oct 22, 2021
1 parent 1857c62 commit 6ab68bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- elb_classic_lb_info - fix empty list returned when names not defined (https://github.com/ansible-collections/community.aws/pull/693).
30 changes: 21 additions & 9 deletions plugins/modules/elb_classic_lb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,34 @@
def list_elbs(connection, load_balancer_names):
results = []

if not load_balancer_names:
for lb in get_all_lb(connection):
results.append(describe_elb(connection, lb))

for load_balancer_name in load_balancer_names:
lb = get_lb(connection, load_balancer_name)
if not lb:
continue
description = camel_dict_to_snake_dict(lb)
name = lb['LoadBalancerName']
instances = lb.get('Instances', [])
description['tags'] = get_tags(connection, name)
description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService')
description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService')
description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown')
description['attributes'] = get_lb_attributes(connection, name)
results.append(description)
results.append(describe_elb(connection, lb))
return results


def describe_elb(connection, lb):
description = camel_dict_to_snake_dict(lb)
name = lb['LoadBalancerName']
instances = lb.get('Instances', [])
description['tags'] = get_tags(connection, name)
description['instances_inservice'], description['instances_inservice_count'] = lb_instance_health(connection, name, instances, 'InService')
description['instances_outofservice'], description['instances_outofservice_count'] = lb_instance_health(connection, name, instances, 'OutOfService')
description['instances_unknownservice'], description['instances_unknownservice_count'] = lb_instance_health(connection, name, instances, 'Unknown')
description['attributes'] = get_lb_attributes(connection, name)
return description


def get_all_lb(connection):
return connection.describe_load_balancers(aws_retry=True)['LoadBalancerDescriptions']


def get_lb(connection, load_balancer_name):
try:
return connection.describe_load_balancers(aws_retry=True, LoadBalancerNames=[load_balancer_name])['LoadBalancerDescriptions'][0]
Expand Down

0 comments on commit 6ab68bb

Please sign in to comment.