awslimitchecker.utils module¶
-
class
awslimitchecker.utils.
StoreKeyValuePair
(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶ Bases:
argparse.Action
Store key=value options in a dict as {‘key’: ‘value’}.
Supports specifying the option multiple times, but NOT with
nargs
.See
Action
.-
__init__
(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
-
__module__
= 'awslimitchecker.utils'¶
-
-
awslimitchecker.utils.
_get_dict_value_by_path
(d, path)[source]¶ Given a dict (
d
) and a list specifying the hierarchical path to a key in that dict (path
), return the value at that path or None if it does not exist.Parameters:
-
awslimitchecker.utils.
_paginate_dict
(result, function_ref, *argv, **kwargs)[source]¶ Paginate through a query that returns a dict result, and return the combined result.
Note that this function requires some special kwargs to be passed in:
- __alc_marker_path__ - The dictionary path to the Marker for the next result set. If this path does not exist, the raw result will be returned.
- __alc_data_path__ - The dictionary path to the list containing the query results. This will be updated with the results of subsequent queries.
- __alc_marker_param__ - The parameter name to pass to
function_ref
with the marker value.
These paths should be lists, in a form usable by
_get_dict_value_by_path()
.All function calls are passed through
invoke_with_throttling_retries()
.Parameters: - result (dict) – the first result from the query
- function_ref (function) – the function to call
- argv (tuple) – the parameters to pass to the function
- kwargs (dict) – keyword arguments to pass to the function
(
invoke_with_throttling_retries()
)
-
awslimitchecker.utils.
_paginate_resultset
(result, function_ref, *argv, **kwargs)[source]¶ Paginate through a query that returns a
boto.resultset.ResultSet
object, and return the combined result.All function calls are passed through
invoke_with_throttling_retries()
.Parameters: - result (
boto.resultset.ResultSet
) – the first ResultSet from the query - function_ref (function) – the function to call
- argv (tuple) – the parameters to pass to the function
- kwargs (dict) – keyword arguments to pass to the function
(
invoke_with_throttling_retries()
)
- result (
-
awslimitchecker.utils.
_set_dict_value_by_path
(d, val, path)[source]¶ Given a dict (
d
), a value (val
), and a list specifying the hierarchical path to a key in that dict (path
), set the value ind
atpath
toval
.Parameters: Raises: TypeError if the path is too short
Returns: the modified dict
-
awslimitchecker.utils.
boto_query_wrapper
(function_ref, *argv, **kwargs)[source]¶ Function to wrap all boto query method calls, for throttling and pagination.
Calls
paginate_query()
and returns the result.Parameters: - function_ref (function) – the function to call
- argv (tuple) – the parameters to pass to the function
- kwargs (dict) – keyword arguments to pass to the function
(
paginate_query()
)
Returns: return value of
function_ref
-
awslimitchecker.utils.
dict2cols
(d, spaces=2, separator=' ')[source]¶ Take a dict of string keys and string values, and return a string with them formatted as two columns separated by at least
spaces
number ofseparator
characters.Parameters:
-
awslimitchecker.utils.
invoke_with_throttling_retries
(function_ref, *argv, **kwargs)[source]¶ Invoke a Boto operation using an exponential backoff in the case of API request throttling.
This is taken from: https://github.com/47lining/ansible-modules-core/blob/2d189f0d192717f83e3c6d37d3fe0988fc329b5a/cloud/amazon/cloudformation.py#L192 see: https://github.com/ansible/ansible-modules-core/pull/224 and https://github.com/ansible/ansible-modules-core/pull/569
To use, transform:
conn.action(args)
into:
invoke_with_throttling_retries(conn.action, args)
Parameters:
-
awslimitchecker.utils.
paginate_query
(function_ref, *argv, **kwargs)[source]¶ Invoke a Boto operation, automatically paginating through all responses.
If
function_ref
returns aboto.resultset.ResultSet
object and itsnext_token
attribute is not None, pass it through to_paginate_resultset()
and return the result.Else if
function_ref
returns a dict, pass it through to_paginate_dict()
and return the result.Else, return the result.
Parameters: - function_ref (function) – the function to call
- argv (tuple) – the parameters to pass to the function
- kwargs (dict) – keyword arguments to pass to the function
(
invoke_with_throttling_retries()
)