Added elasticsearch and autoscaling for in-use check

This commit is contained in:
AJ Bahnken 2018-02-12 13:20:14 -08:00
Родитель ed4f8e27bd
Коммит d64ea41b2d
3 изменённых файлов: 41 добавлений и 22 удалений

Просмотреть файл

@ -0,0 +1,10 @@
from conftest import botocore_client
def autoscaling_launch_configurations():
"http://botocore.readthedocs.io/en/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations"
return botocore_client.get(
'autoscaling', 'describe_launch_configurations', [], {})\
.extract_key('LaunchConfigurations')\
.flatten()\
.values()

Просмотреть файл

@ -2,6 +2,7 @@ from collections import defaultdict
from conftest import botocore_client
from aws.autoscaling.resources import autoscaling_launch_configurations
from aws.elasticache.resources import elasticache_clusters
from aws.elb.resources import (
elbs,
@ -44,26 +45,30 @@ def ec2_ebs_volumes():
def ec2_security_groups_with_in_use_flag():
"""Returns security groups with an additional "InUse" key,
which is True if it is associated with at least one EC2
instance.
which is True if it is associated with at least one resource.
Possible resources:
- EC2
- ELBs (v1 and v2)
- RDS
- Redshift
- ElasticCache
- ElasticSearchService
- AutoScaling
"""
sec_groups = ec2_security_groups()
resources = sum([ec2_instances(), elbs(), elbs_v2(), elasticache_clusters()], [])
resources = sum([
ec2_instances(),
elbs(),
elbs_v2(),
elasticache_clusters(),
autoscaling_launch_configurations()
], [])
vpc_namespaced_resources = sum([rds_db_instances(), redshift_clusters()], [])
# Included:
# - ELBs (v1 and v2?)
# - RDS
# - Redshift
# - ElasticCache
# TODO:
# Need to include:
# - AutoScaling (describe_launch_configurations)
#
# - ElasticSearchService
# - Are these just ec2 instances?
# - EMR?
# - Are these just ec2 instances?
@ -82,8 +87,9 @@ def ec2_security_groups_with_in_use_flag():
in_use_sec_group_ids[attached_sec_group['VpcSecurityGroupId']] += 1
for domain in elasticsearch_domains():
for attached_sec_group in domain['VPCOptions']['SecurityGroupIds']:
in_use_sec_group_ids[attached_sec_group] += 1
if 'VPCOptions' in domain:
for attached_sec_group in domain['VPCOptions']['SecurityGroupIds']:
in_use_sec_group_ids[attached_sec_group] += 1
for sec_group in sec_groups:
if sec_group["GroupId"] in in_use_sec_group_ids.keys():

Просмотреть файл

@ -5,13 +5,16 @@ def elasticsearch_domains():
"""
http://botocore.readthedocs.io/en/latest/reference/services/es.html#ElasticsearchService.Client.describe_elasticsearch_domains
"""
domains = list_elasticsearch_domains()
print(domains)
return botocore_client.get(
'es', 'describe_elasticsearch_domains', [], {'DomainNames': domains})\
.extract_key('DomainStatusList')\
.flatten()\
.values()
# You can only get 5 at a time.
domains_list = list_elasticsearch_domains()
domains = []
for i in range(0, len(domains_list), 5):
domains += botocore_client.get(
'es', 'describe_elasticsearch_domains', [], {'DomainNames': domains_list[i:i+5]})\
.extract_key('DomainStatusList')\
.flatten()\
.values()
return domains
def list_elasticsearch_domains():