INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Query EC2's DescribeAccountAttributes API action, and update limits
with the quotas returned. Updates ``self.limits``. | def _update_limits_from_api(self):
"""
Query EC2's DescribeAccountAttributes API action, and update limits
with the quotas returned. Updates ``self.limits``.
"""
self.connect()
logger.info("Querying EC2 DescribeAccountAttributes for limits")
lims = self.conn.descr... |
Find the ECS service usage for clusters. Calls
:py:meth:`~._find_usage_one_cluster` for each cluster. | def _find_usage_clusters(self):
"""
Find the ECS service usage for clusters. Calls
:py:meth:`~._find_usage_one_cluster` for each cluster.
"""
count = 0
fargate_task_count = 0
paginator = self.conn.get_paginator('list_clusters')
for page in paginator.pagina... |
Find usage for services in each cluster.
:param cluster_name: name of the cluster to find usage for
:type cluster_name: str | def _find_usage_one_cluster(self, cluster_name):
"""
Find usage for services in each cluster.
:param cluster_name: name of the cluster to find usage for
:type cluster_name: str
"""
tps_lim = self.limits['EC2 Tasks per Service (desired count)']
paginator = self.co... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
Find usage on APIs / RestAPIs, and resources that are limited per-API.
Update `self.limits`. | def _find_usage_apis(self):
"""
Find usage on APIs / RestAPIs, and resources that are limited per-API.
Update `self.limits`.
"""
api_ids = []
logger.debug('Finding usage for APIs')
regional_count = 0
private_count = 0
edge_count = 0
paginat... |
Find usage on API Keys.
Update `self.limits`. | def _find_usage_api_keys(self):
"""
Find usage on API Keys.
Update `self.limits`.
"""
logger.debug('Finding usage for API Keys')
key_count = 0
paginator = self.conn.get_paginator('get_api_keys')
for resp in paginator.paginate():
key_count += le... |
Find usage on Client Certificates. Update `self.limits`. | def _find_usage_certs(self):
"""
Find usage on Client Certificates. Update `self.limits`.
"""
logger.debug('Finding usage for Client Certificates')
cert_count = 0
paginator = self.conn.get_paginator('get_client_certificates')
for resp in paginator.paginate():
... |
Find usage on VPC Links. Update `self.limits`. | def _find_usage_vpc_links(self):
"""
Find usage on VPC Links. Update `self.limits`.
"""
logger.debug('Finding usage for VPC Links')
link_count = 0
paginator = self.conn.get_paginator('get_vpc_links')
for resp in paginator.paginate():
link_count += len(... |
Find usage on Usage Plans and plans per API Key. Update `self.limits`. | def _find_usage_plans(self):
"""
Find usage on Usage Plans and plans per API Key. Update `self.limits`.
"""
logger.debug('Finding usage for Usage Plans')
plan_count = 0
paginator = self.conn.get_paginator('get_usage_plans')
for resp in paginator.paginate():
... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
Call :py:meth:`~.connect` and then check what region we're running in;
adjust default limits as required for regions that differ (us-east-1). | def _update_limits_from_api(self):
"""
Call :py:meth:`~.connect` and then check what region we're running in;
adjust default limits as required for regions that differ (us-east-1).
"""
region_limits = {
'us-east-1': 70
}
self.connect()
rname = ... |
Poll 'Service Limits' check results from Trusted Advisor, if possible.
Iterate over all :py:class:`~.AwsLimit` objects for the given services
and update their limits from TA if present in TA checks.
:param services: dict of service name (string) to
:py:class:`~._AwsService` objects
... | def update_limits(self):
"""
Poll 'Service Limits' check results from Trusted Advisor, if possible.
Iterate over all :py:class:`~.AwsLimit` objects for the given services
and update their limits from TA if present in TA checks.
:param services: dict of service name (string) to
... |
Poll Trusted Advisor (Support) API for limit checks.
Return a dict of service name (string) keys to nested dict vals, where
each key is a limit name and each value the current numeric limit.
e.g.:
::
{
'EC2': {
'SomeLimit': 10,
... | def _poll(self):
"""
Poll Trusted Advisor (Support) API for limit checks.
Return a dict of service name (string) keys to nested dict vals, where
each key is a limit name and each value the current numeric limit.
e.g.:
::
{
'EC2': {
... |
Query currently-available TA checks, return the check ID and metadata
of the 'performance/Service Limits' check.
:returns: 2-tuple of Service Limits TA check ID (string),
metadata (list), or (None, None).
:rtype: tuple | def _get_limit_check_id(self):
"""
Query currently-available TA checks, return the check ID and metadata
of the 'performance/Service Limits' check.
:returns: 2-tuple of Service Limits TA check ID (string),
metadata (list), or (None, None).
:rtype: tuple
"""
... |
Given the ``check_id``, return the dict of Trusted Advisor check
results. This handles refreshing the Trusted Advisor check, if desired,
according to ``self.refresh_mode`` and ``self.refresh_timeout``.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:returns: d... | def _get_refreshed_check_result(self, check_id):
"""
Given the ``check_id``, return the dict of Trusted Advisor check
results. This handles refreshing the Trusted Advisor check, if desired,
according to ``self.refresh_mode`` and ``self.refresh_timeout``.
:param check_id: the Tru... |
Given a Trusted Advisor check_id that has just been refreshed, poll
until the refresh is complete. Once complete, return the check result.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:returns: dict check result. The return value of
:py:meth:`Support.Clien... | def _poll_for_refresh(self, check_id):
"""
Given a Trusted Advisor check_id that has just been refreshed, poll
until the refresh is complete. Once complete, return the check result.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:returns: dict check re... |
Determine if the given check_id can be refreshed yet.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:return: whether or not the check can be refreshed yet
:rtype: bool | def _can_refresh_check(self, check_id):
"""
Determine if the given check_id can be refreshed yet.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:return: whether or not the check can be refreshed yet
:rtype: bool
"""
try:
re... |
Directly wrap
:py:meth:`Support.Client.describe_trusted_advisor_check_result`;
return a 2-tuple of the result dict and the last refresh DateTime.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:return: 2-tuple of (result dict, last refresh DateTime). If the la... | def _get_check_result(self, check_id):
"""
Directly wrap
:py:meth:`Support.Client.describe_trusted_advisor_check_result`;
return a 2-tuple of the result dict and the last refresh DateTime.
:param check_id: the Trusted Advisor check ID
:type check_id: str
:return:... |
Given a dict of TrustedAdvisor check results from :py:meth:`~._poll`
and a dict of Service objects passed in to :py:meth:`~.update_limits`,
updated the TrustedAdvisor limits for all services.
:param ta_results: results returned by :py:meth:`~._poll`
:type ta_results: dict
:param... | def _update_services(self, ta_results):
"""
Given a dict of TrustedAdvisor check results from :py:meth:`~._poll`
and a dict of Service objects passed in to :py:meth:`~.update_limits`,
updated the TrustedAdvisor limits for all services.
:param ta_results: results returned by :py:... |
Build our service and limits dict. This is laid out identical to
``self.all_services``, but keys limits by their ``ta_service_name``
and ``ta_limit_name`` properties.
:return: dict of TA service names to TA limit names to AwsLimit objects. | def _make_ta_service_dict(self):
"""
Build our service and limits dict. This is laid out identical to
``self.all_services``, but keys limits by their ``ta_service_name``
and ``ta_limit_name`` properties.
:return: dict of TA service names to TA limit names to AwsLimit objects.
... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
find usage for ElasticBeanstalk applications | def _find_usage_applications(self):
"""find usage for ElasticBeanstalk applications"""
applications = self.conn.describe_applications()
self.limits['Applications']._add_current_usage(
len(applications['Applications']),
aws_type='AWS::ElasticBeanstalk::Application',
... |
find usage for ElasticBeanstalk application verions | def _find_usage_application_versions(self):
"""find usage for ElasticBeanstalk application verions"""
versions = self.conn.describe_application_versions()
self.limits['Application versions']._add_current_usage(
len(versions['ApplicationVersions']),
aws_type='AWS::ElasticB... |
find usage for ElasticBeanstalk environments | def _find_usage_environments(self):
"""find usage for ElasticBeanstalk environments"""
environments = self.conn.describe_environments()
self.limits['Environments']._add_current_usage(
len(environments['Environments']),
aws_type='AWS::ElasticBeanstalk::Environment',
... |
format command output for docs | def format_cmd_output(cmd, output, name):
"""format command output for docs"""
formatted = '.. code-block:: console\n\n'
formatted += ' (venv)$ {c}\n'.format(c=cmd)
lines = output.split("\n")
if name != 'help':
for idx, line in enumerate(lines):
if len(line) > 100:
... |
Trigger rebuild of all documentation that is dynamically generated
from awslimitchecker. | def build_docs():
"""
Trigger rebuild of all documentation that is dynamically generated
from awslimitchecker.
"""
if os.environ.get('CI', None) is not None:
print("Not building dynamic docs in CI environment")
raise SystemExit(0)
region = os.environ.get('AWS_DEFAULT_REGION', Non... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
find usage for VPCs | def _find_usage_vpcs(self):
"""find usage for VPCs"""
# overall number of VPCs
vpcs = self.conn.describe_vpcs()
self.limits['VPCs']._add_current_usage(
len(vpcs['Vpcs']),
aws_type='AWS::EC2::VPC'
) |
find usage for Subnets; return dict of SubnetId to AZ | def _find_usage_subnets(self):
"""find usage for Subnets; return dict of SubnetId to AZ"""
# subnets per VPC
subnet_to_az = {}
subnets = defaultdict(int)
for subnet in self.conn.describe_subnets()['Subnets']:
subnets[subnet['VpcId']] += 1
subnet_to_az[subn... |
find usage for ACLs | def _find_usage_ACLs(self):
"""find usage for ACLs"""
# Network ACLs per VPC
acls = defaultdict(int)
for acl in self.conn.describe_network_acls()['NetworkAcls']:
acls[acl['VpcId']] += 1
# Rules per network ACL
self.limits['Rules per network ACL']._add_... |
find usage for route tables | def _find_usage_route_tables(self):
"""find usage for route tables"""
# Route tables per VPC
tables = defaultdict(int)
for table in self.conn.describe_route_tables()['RouteTables']:
tables[table['VpcId']] += 1
# Entries per route table
routes = [
... |
find usage for Internet Gateways | def _find_usage_gateways(self):
"""find usage for Internet Gateways"""
# Internet gateways
gws = self.conn.describe_internet_gateways()
self.limits['Internet gateways']._add_current_usage(
len(gws['InternetGateways']),
aws_type='AWS::EC2::InternetGateway',
... |
find usage for NAT Gateways
:param subnet_to_az: dict mapping subnet ID to AZ
:type subnet_to_az: dict | def _find_usage_nat_gateways(self, subnet_to_az):
"""
find usage for NAT Gateways
:param subnet_to_az: dict mapping subnet ID to AZ
:type subnet_to_az: dict
"""
# currently, some regions (sa-east-1 as one example) don't have NAT
# Gateway service; they return an ... |
find usage of vpn gateways | def _find_usages_vpn_gateways(self):
"""find usage of vpn gateways"""
# do not include deleting and deleted in the results
vpngws = self.conn.describe_vpn_gateways(Filters=[
{
'Name': 'state',
'Values': [
'available',
... |
find usage of network interfaces | def _find_usage_network_interfaces(self):
"""find usage of network interfaces"""
enis = paginate_dict(
self.conn.describe_network_interfaces,
alc_marker_path=['NextToken'],
alc_data_path=['NetworkInterfaces'],
alc_marker_param='NextToken'
)
... |
Query EC2's DescribeAccountAttributes API action and
update the network interface limit, as needed. Updates ``self.limits``.
More info on the network interface limit, from the docs:
'This limit is the greater of either the default limit (350) or your
On-Demand Instance limit multiplied ... | def _update_limits_from_api(self):
"""
Query EC2's DescribeAccountAttributes API action and
update the network interface limit, as needed. Updates ``self.limits``.
More info on the network interface limit, from the docs:
'This limit is the greater of either the default limit (35... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information. | def _update_limits_from_api(self):
"""
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information.
"""
logger.debug('Setting DirectoryService limits from API')
self.connect()
resp = self.... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
ignore_statuses = [
'DELETE_COMPLETE'
]
logger.debug("Checking usage for serv... |
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information. | def _update_limits_from_api(self):
"""
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information.
"""
logger.debug('Setting CloudFormation limits from API')
self.connect()
resp = self.co... |
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.
:param limit_value: the new limit value
:type limit_value: int
... | def set_limit_override(self, limit_value, override_ta=True):
"""
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.
... |
Return :py:const:`~awslimitchecker.limit.SOURCE_DEFAULT` if
:py:meth:`~.get_limit` returns the default limit,
:py:const:`~awslimitchecker.limit.SOURCE_OVERRIDE` if it returns a
manually-overridden limit,
:py:const:`~awslimitchecker.limit.SOURCE_TA` if it returns a limit from
Trus... | def get_limit_source(self):
"""
Return :py:const:`~awslimitchecker.limit.SOURCE_DEFAULT` if
:py:meth:`~.get_limit` returns the default limit,
:py:const:`~awslimitchecker.limit.SOURCE_OVERRIDE` if it returns a
manually-overridden limit,
:py:const:`~awslimitchecker.limit.SO... |
Returns the effective limit value for this Limit,
taking into account limit overrides and Trusted
Advisor data. None is returned for limits that are
explicitly unlimited.
:returns: effective limit value, ``int`` or ``None`` | def get_limit(self):
"""
Returns the effective limit value for this Limit,
taking into account limit overrides and Trusted
Advisor data. None is returned for limits that are
explicitly unlimited.
:returns: effective limit value, ``int`` or ``None``
"""
li... |
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 :py:meth:`~.AwsLimitUsage.__str__` value.
If the limit has mo... | def get_current_usage_str(self):
"""
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 :py:meth:`~.AwsLi... |
Add a new current usage value for this limit.
Creates a new :py:class:`~.AwsLimitUsage` instance and
appends it to the internal list. If more than one usage value
is given to this service, they should have ``id`` and
``aws_type`` set.
This method should only be called from the ... | def _add_current_usage(self, value, maximum=None, resource_id=None,
aws_type=None):
"""
Add a new current usage value for this limit.
Creates a new :py:class:`~.AwsLimitUsage` instance and
appends it to the internal list. If more than one usage value
i... |
Get the warning and critical thresholds for this Limit.
Return type is a 4-tuple of:
1. warning integer (usage) threshold, or None
2. warning percent threshold
3. critical integer (usage) threshold, or None
4. critical percent threshold
:rtype: tuple | def _get_thresholds(self):
"""
Get the warning and critical thresholds for this Limit.
Return type is a 4-tuple of:
1. warning integer (usage) threshold, or None
2. warning percent threshold
3. critical integer (usage) threshold, or None
4. critical percent thre... |
Override the default warning and critical thresholds used to evaluate
this limit's usage. Theresholds can be specified as a percentage
of the limit, or as a usage count, or both.
**Note:** The percent thresholds (``warn_percent`` and ``crit_percent``)
have default values that are set gl... | def set_threshold_override(self, warn_percent=None, warn_count=None,
crit_percent=None, crit_count=None):
"""
Override the default warning and critical thresholds used to evaluate
this limit's usage. Theresholds can be specified as a percentage
of the limit... |
Check this limit's current usage against the specified default
thresholds, and any custom theresholds that have been set on the
class instance. Return True if usage is within thresholds, or false if
warning or critical thresholds have been surpassed.
This method sets internal variables ... | def check_thresholds(self):
"""
Check this limit's current usage against the specified default
thresholds, and any custom theresholds that have been set on the
class instance. Return True if usage is within thresholds, or false if
warning or critical thresholds have been surpasse... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect()
for lim i... |
find usage for cache nodes | def _find_usage_nodes(self):
"""find usage for cache nodes"""
nodes = 0
paginator = self.conn.get_paginator('describe_cache_clusters')
for page in paginator.paginate(ShowCacheNodeInfo=True):
for cluster in page['CacheClusters']:
try:
num_no... |
find usage for elasticache parameter groups | def _find_usage_parameter_groups(self):
"""find usage for elasticache parameter groups"""
num_groups = 0
paginator = self.conn.get_paginator('describe_cache_parameter_groups')
for page in paginator.paginate():
for group in page['CacheParameterGroups']:
num_gr... |
find usage for elasticache security groups | def _find_usage_security_groups(self):
"""find usage for elasticache security groups"""
num_groups = 0
# If EC2-Classic isn't available (e.g., a new account)
# this method will fail with:
# Code: "InvalidParameterValue"
# Message: "Use of cache security groups is n... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
for lim in self.limits.values():... |
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict | def get_limits(self):
"""
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict
"""
if self.limits != {}:
return self.limits
... |
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information. | def _update_limits_from_api(self):
"""
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information.
"""
self.connect_resource()
summary = self.resource_conn.AccountSummary()
for k, v in so... |
parse arguments/options
:param argv: argument list to parse, usually ``sys.argv[1:]``
:type argv: list
:returns: parsed arguments
:rtype: :py:class:`argparse.Namespace` | def parse_args(self, argv):
"""
parse arguments/options
:param argv: argument list to parse, usually ``sys.argv[1:]``
:type argv: list
:returns: parsed arguments
:rtype: :py:class:`argparse.Namespace`
"""
desc = 'Report on AWS service limits and usage via... |
:param service_name: the name of the service
:type service_name: str
:param limit: the Limit this relates to
:type limit: :py:class:`~.AwsLimit`
:param crits: the specific usage values that crossed the critical
threshold
:type usage: :py:obj:`list` of :py:class:`~.AwsLi... | def print_issue(self, service_name, limit, crits, warns):
"""
:param service_name: the name of the service
:type service_name: str
:param limit: the Limit this relates to
:type limit: :py:class:`~.AwsLimit`
:param crits: the specific usage values that crossed the critical... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
for lim in self.limits.values():... |
Find usage for ELBv1 / Classic ELB and update the appropriate limits.
:returns: number of Classic ELBs in use
:rtype: int | def _find_usage_elbv1(self):
"""
Find usage for ELBv1 / Classic ELB and update the appropriate limits.
:returns: number of Classic ELBs in use
:rtype: int
"""
logger.debug("Checking usage for ELBv1")
self.connect()
lbs = paginate_dict(
self.co... |
Find usage for ELBv2 / Application LB and update the appropriate limits.
:returns: number of Application LBs in use
:rtype: int | def _find_usage_elbv2(self):
"""
Find usage for ELBv2 / Application LB and update the appropriate limits.
:returns: number of Application LBs in use
:rtype: int
"""
logger.debug('Checking usage for ELBv2')
conn2 = client(
'elbv2',
config=C... |
Update usage for a single ALB.
:param conn: elbv2 API connection
:type conn: :py:class:`ElasticLoadBalancing.Client`
:param alb_arn: Load Balancer ARN
:type alb_arn: str
:param alb_name: Load Balancer Name
:type alb_name: str | def _update_usage_for_alb(self, conn, alb_arn, alb_name):
"""
Update usage for a single ALB.
:param conn: elbv2 API connection
:type conn: :py:class:`ElasticLoadBalancing.Client`
:param alb_arn: Load Balancer ARN
:type alb_arn: str
:param alb_name: Load Balancer ... |
Update usage for a single NLB.
:param conn: elbv2 API connection
:type conn: :py:class:`ElasticLoadBalancing.Client`
:param nlb_arn: Load Balancer ARN
:type nlb_arn: str
:param nlb_name: Load Balancer Name
:type nlb_name: str | def _update_usage_for_nlb(self, conn, nlb_arn, nlb_name):
"""
Update usage for a single NLB.
:param conn: elbv2 API connection
:type conn: :py:class:`ElasticLoadBalancing.Client`
:param nlb_arn: Load Balancer ARN
:type nlb_arn: str
:param nlb_name: Load Balancer ... |
Query ELB's DescribeAccountLimits API action, and update limits
with the quotas returned. Updates ``self.limits``. | def _update_limits_from_api(self):
"""
Query ELB's DescribeAccountLimits API action, and update limits
with the quotas returned. Updates ``self.limits``.
"""
self.connect()
logger.debug("Querying ELB DescribeAccountLimits for limits")
attribs = self.conn.describe_... |
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.
... | def paginate_dict(function_ref, *argv, **kwargs):
"""
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. ... |
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 of
``separator`` characters.
:param d: dict of string keys, string values
:type d: dict
:param spaces: number of spaces to separate columns by
:type space... | def dict2cols(d, spaces=2, separator=' '):
"""
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 of
``separator`` characters.
:param d: dict of string keys, string values
:type d: dict
:param spaces: ... |
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.
:param d: the dict to search in
:type d: dict
:param path: the path to the key in the dict
:type path: list | def _get_dict_value_by_path(d, path):
"""
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.
:param d: the dict to search in
:type d: dict
:param path: the path to the key in the dict... |
Given a dict (``d``), a value (``val``), and a list specifying the
hierarchical path to a key in that dict (``path``), set the value in ``d``
at ``path`` to ``val``.
:param d: the dict to search in
:type d: dict
:param path: the path to the key in the dict
:type path: list
:raises: TypeErr... | def _set_dict_value_by_path(d, val, path):
"""
Given a dict (``d``), a value (``val``), and a list specifying the
hierarchical path to a key in that dict (``path``), set the value in ``d``
at ``path`` to ``val``.
:param d: the dict to search in
:type d: dict
:param path: the path to the ke... |
Generate keyword arguments for boto3 connection functions.
If ``self.account_id`` is defined, this will call
:py:meth:`~._get_sts_token` to get STS token credentials using
`boto3.STS.Client.assume_role <https://boto3.readthedocs.org/en/
latest/reference/services/sts.html#STS.Client.assu... | def _boto_conn_kwargs(self):
"""
Generate keyword arguments for boto3 connection functions.
If ``self.account_id`` is defined, this will call
:py:meth:`~._get_sts_token` to get STS token credentials using
`boto3.STS.Client.assume_role <https://boto3.readthedocs.org/en/
l... |
Assume a role via STS and return the credentials.
First connect to STS via :py:func:`boto3.client`, then
assume a role using `boto3.STS.Client.assume_role <https://boto3.readthe
docs.org/en/latest/reference/services/sts.html#STS.Client.assume_role>`_
using ``self.account_id`` and ``self... | def _get_sts_token(self):
"""
Assume a role via STS and return the credentials.
First connect to STS via :py:func:`boto3.client`, then
assume a role using `boto3.STS.Client.assume_role <https://boto3.readthe
docs.org/en/latest/reference/services/sts.html#STS.Client.assume_role>`... |
For each limit in the specified service (or all services if
``service`` is ``None``), query the AWS API via ``boto3``
and find the current usage amounts for that limit.
This method updates the ``current_usage`` attribute of the
:py:class:`~.AwsLimit` objects for each service, which can
... | def find_usage(self, service=None, use_ta=True):
"""
For each limit in the specified service (or all services if
``service`` is ``None``), query the AWS API via ``boto3``
and find the current usage amounts for that limit.
This method updates the ``current_usage`` attribute of th... |
Set manual overrides on AWS service limits, i.e. if you
had limits increased by AWS support. This takes a dict in
the same form as that returned by :py:meth:`~.get_limits`,
i.e. service_name (str) keys to nested dict of limit_name
(str) to limit value (int) like:
::
... | def set_limit_overrides(self, override_dict, override_ta=True):
"""
Set manual overrides on AWS service limits, i.e. if you
had limits increased by AWS support. This takes a dict in
the same form as that returned by :py:meth:`~.get_limits`,
i.e. service_name (str) keys to nested ... |
Set a manual override on an AWS service limits, i.e. if you
had limits increased by AWS support.
This method calls :py:meth:`._AwsService.set_limit_override`
on the corresponding _AwsService instance.
Explicitly set limit overrides using this method will take
precedence over de... | def set_limit_override(self, service_name, limit_name,
value, override_ta=True):
"""
Set a manual override on an AWS service limits, i.e. if you
had limits increased by AWS support.
This method calls :py:meth:`._AwsService.set_limit_override`
on the co... |
Set manual overrides on the threshold (used for determining
warning/critical status) a dict of limits. See
:py:class:`~.AwsLimitChecker` for information on Warning and
Critical thresholds.
Dict is composed of service name keys (string) to dict of
limit names (string), to dict of... | def set_threshold_overrides(self, override_dict):
"""
Set manual overrides on the threshold (used for determining
warning/critical status) a dict of limits. See
:py:class:`~.AwsLimitChecker` for information on Warning and
Critical thresholds.
Dict is composed of service ... |
Set a manual override on the threshold (used for determining
warning/critical status) for a specific limit. See
:py:class:`~.AwsLimitChecker` for information on Warning and
Critical thresholds.
See :py:meth:`.AwsLimit.set_threshold_override`.
:param service_name: the name of th... | def set_threshold_override(self, service_name, limit_name,
warn_percent=None, warn_count=None,
crit_percent=None, crit_count=None):
"""
Set a manual override on the threshold (used for determining
warning/critical status) for a specif... |
Check all limits and current usage against their specified thresholds;
return all :py:class:`~.AwsLimit` instances that have crossed
one or more of their thresholds.
If ``service`` is specified, the returned dict has one element,
the service name, whose value is a nested dict as describ... | def check_thresholds(self, service=None, use_ta=True):
"""
Check all limits and current usage against their specified thresholds;
return all :py:class:`~.AwsLimit` instances that have crossed
one or more of their thresholds.
If ``service`` is specified, the returned dict has one... |
Return an IAM policy granting all of the permissions needed for
awslimitchecker to fully function. This returns a dict suitable
for json serialization to a valid IAM policy.
Internally, this calls :py:meth:`~._AwsService.required_iam_permissions`
on each :py:class:`~._AwsService` instan... | def get_required_iam_policy(self):
"""
Return an IAM policy granting all of the permissions needed for
awslimitchecker to fully function. This returns a dict suitable
for json serialization to a valid IAM policy.
Internally, this calls :py:meth:`~._AwsService.required_iam_permis... |
Query Route53's GetHostedZoneLimit API action, and update limits
with the quotas returned. Updates ``self.limits``. | def _update_limits_from_api(self):
"""
Query Route53's GetHostedZoneLimit API action, and update limits
with the quotas returned. Updates ``self.limits``.
"""
logger.info("Querying Route53 GetHostedZoneLimits for limits")
self.connect()
self._find_limit_hosted_zon... |
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
Limits from:
docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict | def get_limits(self):
"""
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
Limits from:
docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html
:returns: dict of limit names to :py:class:`~.AwsLimit` obj... |
Return all available hosted zones
:returns: dict of hosted zones
:rtype: dict | def _get_hosted_zones(self):
"""
Return all available hosted zones
:returns: dict of hosted zones
:rtype: dict
"""
results = paginate_dict(
self.conn.list_hosted_zones,
alc_marker_path=['NextMarker'],
alc_data_path=['HostedZones'],
... |
Return a hosted zone limit [recordsets|vpc_associations]
:rtype: dict | def _get_hosted_zone_limit(self, limit_type, hosted_zone_id):
"""
Return a hosted zone limit [recordsets|vpc_associations]
:rtype: dict
"""
result = self.conn.get_hosted_zone_limit(
Type=limit_type,
HostedZoneId=hosted_zone_id
)
return r... |
Calculate the max recordsets and vpc associations and the current values
per hosted zone | def _find_limit_hosted_zone(self):
"""
Calculate the max recordsets and vpc associations and the current values
per hosted zone
"""
for limit_type in [self.MAX_RRSETS_BY_ZONE,
self.MAX_VPCS_ASSOCIATED_BY_ZONE]:
self.limits[limit_type["name"]... |
Return the current IAM policy as a json-serialized string | def get_iam_policy(self):
"""Return the current IAM policy as a json-serialized string"""
checker = AwsLimitChecker()
policy = checker.get_required_iam_policy()
return json.dumps(policy, sort_keys=True, indent=2) |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect_resource()
... |
Check GitHub for a release with the specified tag name. If present,
return a 2-tuple of the release name and release HTML URL. Otherwise,
return a 2-tuple of None, None (tag not present).
:param version: the tag name to check for
:type version: str
:return: 2-tuple of release na... | def get_tag(self, version):
"""
Check GitHub for a release with the specified tag name. If present,
return a 2-tuple of the release name and release HTML URL. Otherwise,
return a 2-tuple of None, None (tag not present).
:param version: the tag name to check for
:type ver... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
for lim in self.limits.values():... |
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information. | def _update_limits_from_api(self):
"""
Call the service's API action to retrieve limit/quota information, and
update AwsLimit objects in ``self.limits`` with this information.
"""
try:
self.connect()
resp = self.conn.get_send_quota()
except Endpoin... |
Connect to an AWS API via boto3 low-level client and set ``self.conn``
to the `boto3.client <https://boto3.readthed
ocs.org/en/latest/reference/core/boto3.html#boto3.client>`_ object
(a ``botocore.client.*`` instance). If ``self.conn`` is not None,
do nothing. This connects to the API na... | def connect(self):
"""
Connect to an AWS API via boto3 low-level client and set ``self.conn``
to the `boto3.client <https://boto3.readthed
ocs.org/en/latest/reference/core/boto3.html#boto3.client>`_ object
(a ``botocore.client.*`` instance). If ``self.conn`` is not None,
... |
Connect to an AWS API via boto3 high-level resource connection and set
``self.resource_conn`` to the `boto3.resource <https://boto3.readthed
ocs.org/en/latest/reference/core/boto3.html#boto3.resource>`_ object
(a ``boto3.resources.factory.*.ServiceResource`` instance).
If ``self.resource... | def connect_resource(self):
"""
Connect to an AWS API via boto3 high-level resource connection and set
``self.resource_conn`` to the `boto3.resource <https://boto3.readthed
ocs.org/en/latest/reference/core/boto3.html#boto3.resource>`_ object
(a ``boto3.resources.factory.*.Service... |
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`. | def find_usage(self):
"""
Determine the current usage for each limit of this service,
and update corresponding Limit via
:py:meth:`~.AwsLimit._add_current_usage`.
"""
logger.debug("Checking usage for service %s", self.service_name)
self.connect_resource()
... |
calculates current usage for all DynamoDB limits | def _find_usage_dynamodb(self):
"""calculates current usage for all DynamoDB limits"""
table_count = 0
region_read_capacity = 0
region_write_capacity = 0
logger.debug("Getting usage for DynamoDB tables")
for table in self.resource_conn.tables.all():
table_cou... |
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict | def get_limits(self):
"""
Return all known limits for this service, as a dict of their names
to :py:class:`~.AwsLimit` objects.
:returns: dict of limit names to :py:class:`~.AwsLimit` objects
:rtype: dict
"""
self.connect()
region_name = self.conn._client... |
Query DynamoDB's DescribeLimits API action, and update limits
with the quotas returned. Updates ``self.limits``. | def _update_limits_from_api(self):
"""
Query DynamoDB's DescribeLimits API action, and update limits
with the quotas returned. Updates ``self.limits``.
"""
self.connect()
logger.info("Querying DynamoDB DescribeLimits for limits")
# no need to paginate
lims... |
The version string for the currently-running awslimitchecker;
includes git branch and tag information.
:rtype: str | def version_str(self):
"""
The version string for the currently-running awslimitchecker;
includes git branch and tag information.
:rtype: str
"""
vs = str(self.release)
if self.tag is not None:
vs += '@{t}'.format(t=self.tag)
elif self.commit ... |
Returns the currently-installed awslimitchecker version, and a best-effort
attempt at finding the origin URL and commit/tag if installed from an
editable git clone.
:returns: awslimitchecker version
:rtype: str | def _get_version_info():
"""
Returns the currently-installed awslimitchecker version, and a best-effort
attempt at finding the origin URL and commit/tag if installed from an
editable git clone.
:returns: awslimitchecker version
:rtype: str
"""
if os.environ.get('VERSIONCHECK_DEBUG', '')... |
load configuration from config/ | def _load_config(self):
"""load configuration from config/"""
logger.debug(
'Listing per-account config subdirectories in %s', self._conf_dir
)
for acct_id in os.listdir(self._conf_dir):
path = os.path.join(self._conf_dir, acct_id)
# skip if not a dire... |
load configuration from one per-account subdirectory | def _load_account(self, acct_id, acct_dir_path):
"""load configuration from one per-account subdirectory"""
# setup a default config dict for the account
self._config[acct_id] = {
'name': None,
'role_name': DEFAULT_ROLE_NAME,
'regions': {}
}
# ... |
load config from a single per-region subdirectory of an account | def _load_region(self, acct_id, region_name, path):
"""load config from a single per-region subdirectory of an account"""
lim_path = os.path.join(path, 'limit_overrides.json')
thresh_path = os.path.join(path, 'threshold_overrides.json')
res = {'limit_overrides': {}, 'threshold_overrides'... |
Return a dictionary of account configuration for the account with the
specified ID or name.
:param id_or_name: ID or name of account
:type id_or_name: str
:return: configuration for specified account
:rtype: dict | def get_account_config(self, id_or_name):
"""
Return a dictionary of account configuration for the account with the
specified ID or name.
:param id_or_name: ID or name of account
:type id_or_name: str
:return: configuration for specified account
:rtype: dict
... |
Run the actual usage and limit check, with overrides, against a specific
account in a specific region, optionally assuming a role in the account
and optionally setting limit and/or threshold overrides.
Return a 2-tuple of lists, warning strings and critical strings.
see: http://awslimi... | def check_limits(self, acct_id, region_name, role_name=None,
limit_overrides={}, threshold_overrides={}):
"""
Run the actual usage and limit check, with overrides, against a specific
account in a specific region, optionally assuming a role in the account
and optional... |
Main entry point. | def run(self, error_on_warning=False, region=None, accounts=[]):
"""
Main entry point.
"""
all_warnings = []
all_criticals = []
if len(accounts) == 0:
# if no accounts specified, run all of them
accounts = self._conf.list_account_ids
for ac... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.