mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[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
This commit is contained in:
parent
b3abab1bd5
commit
1699c9ea48
1 changed files with 21 additions and 11 deletions
|
@ -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 = []
|
||||
elb_array, token = [], None
|
||||
|
||||
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))
|
||||
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)
|
||||
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…
Reference in a new issue