[cloud] Remove custom pagination function in ec2_launchconfig module (#28574)

This commit is contained in:
Sloane Hertel 2017-08-29 13:52:45 -04:00 committed by Ryan Brown
parent 9822db610b
commit e05eebcb50
2 changed files with 3 additions and 34 deletions

View file

@ -332,37 +332,6 @@ def ec2_connect(module):
return ec2
def paging(pause=0, marker_property='marker', result_key=None):
""" Adds paging to boto retrieval functions that support a 'marker'
this is configurable as not all boto functions seem to use the
same name.
"""
def wrapper(f):
def page(*args, **kwargs):
results = []
marker = None
while True:
try:
if marker:
kwargs[marker_property] = marker
new = f(*args, **kwargs)
marker = new.get(marker_property)
if result_key:
new = new[result_key]
results.extend(new)
if not marker:
break
elif pause:
sleep(pause)
except TypeError:
# Older version of boto do not allow for marker param, just run normally
results = f(*args, **kwargs)
break
return results
return page
return wrapper
def _camel_to_snake(name):
def prepend_underscore_and_lower(m):

View file

@ -165,7 +165,7 @@ except ImportError:
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (HAS_BOTO3, boto3_conn, camel_dict_to_snake_dict, ec2_argument_spec,
get_aws_connection_info, paging)
get_aws_connection_info)
def list_launch_configs(connection, module):
@ -177,8 +177,8 @@ def list_launch_configs(connection, module):
sort_end = module.params.get('sort_end')
try:
launch_configs = {'LaunchConfigurations': paging(pause=0, marker_property='NextToken', result_key='LaunchConfigurations')
(connection.describe_launch_configurations)(LaunchConfigurationNames=launch_config_name)}
pg = connection.get_paginator('describe_launch_configurations')
launch_configs = pg.paginate(LaunchConfigurationNames=launch_config_name).build_full_result()
except ClientError as e:
module.fail_json(msg=e.message)