[cloud] ec2_elb_facts fails on accounts with to many ELBs (#21602)

The list_elbs call to boto doesn't use any pagination, so any time there
are more ELBs than the API page size, this module will fail. This change
uses the `next_token` attribute of `ResultSet` to check if there are
still more ELBs to return.

Fixes #21361
pull/22020/head
Ryan Brown 8 years ago committed by GitHub
parent b3abab1bd5
commit 1699c9ea48

@ -78,6 +78,8 @@ EXAMPLES = '''
'''
import traceback
try:
import boto.ec2.elb
from boto.ec2.tag import Tag
@ -201,20 +203,28 @@ class ElbInformation(object):
def list_elbs(self):
elb_array = []
try:
all_elbs = self.connection.get_all_load_balancers()
except BotoServerError as err:
self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message))
elb_array, token = [], None
if all_elbs:
if self.names:
for existing_lb in all_elbs:
if existing_lb.name in self.names:
elb_array.append(existing_lb)
while True:
try:
all_elbs = self.connection.get_all_load_balancers(marker=token)
token = all_elbs.next_token
except BotoServerError as err:
self.module.fail_json(msg = "%s: %s" % (err.error_code, err.error_message),
exception=traceback.format_exc())
if all_elbs:
if self.names:
for existing_lb in all_elbs:
if existing_lb.name in self.names:
elb_array.append(existing_lb)
else:
elb_array.extend(all_elbs)
else:
elb_array = all_elbs
break
if token is None:
break
return list(map(self._get_elb_info, elb_array))

Loading…
Cancel
Save