awslimitchecker.services.base module

class awslimitchecker.services.base._AwsService(warning_threshold, critical_threshold)[source]

Bases: object

Describes an AWS service and its limits, and provides methods to query current utilization.

Constructors of _AwsService subclasses must not make any external connections; these must be made lazily as needed in other methods. _AwsService subclasses should be usable without any external network connections.

Parameters:
  • warning_threshold (int) – the default warning threshold, as an integer percentage, for any limits without a specifically-set threshold.
  • critical_threshold (int) – the default critical threshold, as an integer percentage, for any limits without a specifically-set threshold.
__abstractmethods__ = frozenset(['get_limits', 'find_usage', 'required_iam_permissions', 'connect'])
__dict__ = dict_proxy({'_abc_cache': <_weakrefset.WeakSet object at 0x7f34b0ab5890>, 'set_limit_override': <function set_limit_override at 0x7f34b0ab92a8>, '__module__': 'awslimitchecker.services.base', 'find_usage': <function find_usage at 0x7f34b0ab9140>, '__metaclass__': <class 'abc.ABCMeta'>, '__abstractmethods__': frozenset(['get_limits', 'find_usage', 'required_iam_permissions', 'connect']), 'set_threshold_override': <function set_threshold_override at 0x7f34b0ab9398>, '_set_ta_limit': <function _set_ta_limit at 0x7f34b0ab9320>, 'service_name': 'baseclass', '_abc_registry': <_weakrefset.WeakSet object at 0x7f34b0ab5810>, 'check_thresholds': <function check_thresholds at 0x7f34b0ab9410>, 'get_limits': <function get_limits at 0x7f34b0ab91b8>, 'required_iam_permissions': <function required_iam_permissions at 0x7f34b0ab9230>, 'connect': <function connect at 0x7f34b0ab90c8>, '_abc_negative_cache': <_weakrefset.WeakSet object at 0x7f34b0ab5910>, '__dict__': <attribute '__dict__' of '_AwsService' objects>, '_abc_negative_cache_version': 25, '__weakref__': <attribute '__weakref__' of '_AwsService' objects>, '__doc__': None, '__init__': <function __init__ at 0x7f34b0ab9050>})
__init__(warning_threshold, critical_threshold)[source]

Describes an AWS service and its limits, and provides methods to query current utilization.

Constructors of _AwsService subclasses must not make any external connections; these must be made lazily as needed in other methods. _AwsService subclasses should be usable without any external network connections.

Parameters:
  • warning_threshold (int) – the default warning threshold, as an integer percentage, for any limits without a specifically-set threshold.
  • critical_threshold (int) – the default critical threshold, as an integer percentage, for any limits without a specifically-set threshold.
__metaclass__

alias of ABCMeta

__module__ = 'awslimitchecker.services.base'
__weakref__

list of weak references to the object (if defined)

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 25
_abc_registry = <_weakrefset.WeakSet object>
_set_ta_limit(limit_name, value)[source]

Set the value for the limit as reported by Trusted Advisor, for the specified limit.

This method should only be called by TrustedAdvisor.

Parameters:
  • limit_name (string) – the name of the limit to override the value for
  • value (int) – the Trusted Advisor limit value
Raises:

ValueError if limit_name is not known to this service

check_thresholds()[source]

Checks current usage against configured thresholds for all limits for this service.

Returns:a dict of limit name to AwsLimit instance for all limits that crossed one or more of their thresholds.
Return type:dict of AwsLimit
connect()[source]

If not already done, establish a connection to the relevant AWS service and save as self.conn.

find_usage()[source]

Determine the current usage for each limit of this service, and update the current_usage property of each corresponding AwsLimit instance.

This method must set self._have_usage = True

get_limits()[source]

Return all known limits for this service, as a dict of their names to AwsLimit objects.

All limits must have self.warning_threshold and self.critical_threshold passed into them.

Returns:dict of limit names to AwsLimit objects
Return type:dict
required_iam_permissions()[source]

Return a list of IAM Actions required for this Service to function properly. All Actions will be shown with an Effect of “Allow” and a Resource of “*”.

Returns:list of IAM Action strings
Return type:list
service_name = 'baseclass'
set_limit_override(limit_name, value, override_ta=True)[source]

Set a new limit value for the specified limit, overriding the default. If override_ta is True, also use this value instead of any found by Trusted Advisor. This method simply passes the data through to the set_limit_override() method of the underlying AwsLimit instance.

Parameters:
  • limit_name (string) – the name of the limit to override the value for
  • value (int) – the new value to set for the limit
  • override_ta (bool) – whether or not to also override Trusted Advisor information
Raises:

ValueError if limit_name is not known to this service

set_threshold_override(limit_name, warn_percent=None, warn_count=None, crit_percent=None, crit_count=None)[source]

Override the default warning and critical thresholds used to evaluate the specified limit’s usage. Theresholds can be specified as a percentage of the limit, or as a usage count, or both.

Parameters:
  • warn_percent (int) – new warning threshold, percentage used
  • warn_count (int) – new warning threshold, actual count/number
  • crit_percent (int) – new critical threshold, percentage used
  • crit_count (int) – new critical threshold, actual count/number