awslimitchecker.limit module¶
-
class
awslimitchecker.limit.
AwsLimit
(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None)[source]¶ Bases:
object
Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.
Parameters: - name (string) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
- service – the
_AwsService
class that this limit is for - default_limit (int) – the default value of this limit for new accounts
- def_warning_threshold (int) – the default warning threshold, as an integer percentage.
- def_critical_threshold (int) – the default critical threshold, as an integer percentage.
- limit_type – the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.
- limit_subtype – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
Raises: ValueError
-
__dict__
= dict_proxy({'set_limit_override': <function set_limit_override at 0x7f9b46a008c0>, '__module__': 'awslimitchecker.limit', 'get_limit': <function get_limit at 0x7f9b46a00a28>, 'get_current_usage_str': <function get_current_usage_str at 0x7f9b46a00b18>, '_set_ta_limit': <function _set_ta_limit at 0x7f9b46a00938>, '__weakref__': <attribute '__weakref__' of 'AwsLimit' objects>, 'check_thresholds': <function check_thresholds at 0x7f9b46a00d70>, 'get_criticals': <function get_criticals at 0x7f9b46a00e60>, 'get_current_usage': <function get_current_usage at 0x7f9b46a00aa0>, '__dict__': <attribute '__dict__' of 'AwsLimit' objects>, 'set_threshold_override': <function set_threshold_override at 0x7f9b46a00cf8>, '_reset_usage': <function _reset_usage at 0x7f9b46a00c08>, 'get_limit_source': <function get_limit_source at 0x7f9b46a009b0>, 'get_warnings': <function get_warnings at 0x7f9b46a00de8>, '_get_thresholds': <function _get_thresholds at 0x7f9b46a00c80>, '_add_current_usage': <function _add_current_usage at 0x7f9b46a00b90>, '__doc__': None, '__init__': <function __init__ at 0x7f9b46a00848>})¶
-
__init__
(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None)[source]¶ Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.
Parameters: - name (string) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
- service – the
_AwsService
class that this limit is for - default_limit (int) – the default value of this limit for new accounts
- def_warning_threshold (int) – the default warning threshold, as an integer percentage.
- def_critical_threshold (int) – the default critical threshold, as an integer percentage.
- limit_type –
the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.
- limit_subtype – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
Raises: ValueError
-
__module__
= 'awslimitchecker.limit'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
_add_current_usage
(value, resource_id=None, aws_type=None)[source]¶ Add a new current usage value for this limit.
Creates a new
AwsLimitUsage
instance and appends it to the internal list. If more than one usage value is given to this service, they should haveid
andaws_type
set.This method should only be called from the
_AwsService
instance that created and manages this Limit.Parameters: - value (
int
orfloat
) – the numeric usage value - resource_id (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (string) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
- value (
-
_get_thresholds
()[source]¶ Get the warning and critical thresholds for this Limit.
Return type is a 4-tuple of:
- warning integer (usage) threshold, or None
- warning percent threshold
- critical integer (usage) threshold, or None
- critical percent threshold
Return type: tuple
-
_set_ta_limit
(limit_value)[source]¶ Set the value for the limit as reported by Trusted Advisor.
This method should only be called by
TrustedAdvisor
.Parameters: limit_value (int) – the Trusted Advisor limit value
-
check_thresholds
()[source]¶ Check this limit’s current usage against the specified default thresholds, and any custom theresholds that have been set on the instance. Return True if usage is within thresholds, or false if warning or critical thresholds have been surpassed.
This method sets internal variables in this instance which can be queried via
get_warnings()
andget_criticals()
to obtain further details about the thresholds that were crossed.Parameters: - default_warning (
int
orfloat
percentage) – default warning threshold in percentage; usage higher than this percent of the limit will be considered a warning - default_critical (
int
orfloat
percentage) – default critical threshold in percentage; usage higher than this percent of the limit will be considered a critical
Returns: False if any thresholds crossed, True otherwise
Return type: - default_warning (
-
get_criticals
()[source]¶ Return a list of
AwsLimitUsage
instances that crossed the critical threshold. These objects are comparable and can be sorted.Return type: list
-
get_current_usage
()[source]¶ Get the current usage for this limit, as a list of
AwsLimitUsage
instances.Returns: list of current usage values Return type: list
ofAwsLimitUsage
-
get_current_usage_str
()[source]¶ Get the a string describing the current usage for this limit.
If no usage has been added for this limit, the result will be “<unknown>”.
If the limit has only one current usage instance, this will be that instance’s
__str__()
value.If the limit has more than one current usage instance, this will be the a string of the form
max: X (Y)
whereX
is the__str__()
value of the instance with the maximum value, andY
is a comma-separated list of the__str__()
values of all usage instances in ascending order.Returns: representation of current usage Return type: string
-
get_limit
()[source]¶ Returns the effective limit value for this Limit, taking into account limit overrides and Trusted Advisor data.
Returns: effective limit value Return type: int
-
get_limit_source
()[source]¶ Return
SOURCE_DEFAULT
ifget_limit()
returns the default limit,SOURCE_OVERRIDE
if it returns a manually-overridden limit, orSOURCE_TA
if it returns a limit from Trusted Advisor.Returns: one of SOURCE_DEFAULT
,SOURCE_OVERRIDE
, orSOURCE_TA
Return type: int
-
get_warnings
()[source]¶ Return a list of
AwsLimitUsage
instances that crossed the warning threshold. These objects are comparable and can be sorted.Return type: list
-
set_limit_override
(limit_value, override_ta=True)[source]¶ Set a new value for this limit, to override the default (such as when AWS Support has increased a limit of yours). If
override_ta
is True, this value will also supersede any found through Trusted Advisor.Parameters:
-
class
awslimitchecker.limit.
AwsLimitUsage
(limit, value, resource_id=None, aws_type=None)[source]¶ Bases:
object
This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.
The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the
AwsLimit
would have one instance of this class for the single value.In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the
AwsLimit
should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.AwsLimitUsage objects are comparable based on their numeric
value
.Parameters: - limit (
AwsLimit
) – the AwsLimit that this instance describes - value (
int
orfloat
) – the numeric usage value - resource_id (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (string) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
-
__dict__
= dict_proxy({'__ne__': <function __ne__ at 0x7f9b46a0a140>, '__module__': 'awslimitchecker.limit', '__weakref__': <attribute '__weakref__' of 'AwsLimitUsage' objects>, '__str__': <function __str__ at 0x7f9b46a0a050>, 'get_value': <function get_value at 0x7f9b46a00f50>, '__init__': <function __init__ at 0x7f9b46a00ed8>, '__gt__': <function __gt__ at 0x7f9b46a0a1b8>, '__dict__': <attribute '__dict__' of 'AwsLimitUsage' objects>, '__lt__': <function __lt__ at 0x7f9b46a0a230>, '__eq__': <function __eq__ at 0x7f9b46a0a0c8>, '__doc__': None, '__ge__': <function __ge__ at 0x7f9b46a0a2a8>})¶
-
__init__
(limit, value, resource_id=None, aws_type=None)[source]¶ This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.
The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the
AwsLimit
would have one instance of this class for the single value.In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the
AwsLimit
should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.AwsLimitUsage objects are comparable based on their numeric
value
.Parameters: - limit (
AwsLimit
) – the AwsLimit that this instance describes - value (
int
orfloat
) – the numeric usage value - resource_id (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
- aws_type (string) –
if
id
is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa
- limit (
-
__module__
= 'awslimitchecker.limit'¶
-
__str__
()[source]¶ Return a string representation of this object.
If
id
is not set, returnvalue
formatted as a string; otherwise, return a string of the formatid=value
.Return type: string
-
__weakref__
¶ list of weak references to the object (if defined)
- limit (
-
awslimitchecker.limit.
SOURCE_DEFAULT
= 0¶ indicates a limit value that came from hard-coded defaults in awslimitchecker
-
awslimitchecker.limit.
SOURCE_OVERRIDE
= 1¶ indicates a limit value that came from user-defined limit overrides
-
awslimitchecker.limit.
SOURCE_TA
= 2¶ indicates a limit value that came from Trusted Advisor