-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.py
48 lines (32 loc) · 1.13 KB
/
test1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import boto3
from tabulate import tabulate
def main():
PROFILES = (#'team_1',
#'team)_2'
)
results = []
id = 0
ALLOWED_PORTS = [80, 443]
for profile in PROFILES:
# we are now looking only on production env
if "_stage" in profile:
continue
print "working on ".format(profile)
session = boto3.Session(profile_name=profile)
sgs = session.client('ec2').describe_instance_status()
for sg in sgs['InstanceStatuses']:
affected_instances = 0
response = session.client('ec2').describe_instances(Filters=[{'Name': 'instance-state-name', 'Values': ['running']},])
for reservation in response['Reservations']:
affected_instances += len(reservation.get('Instances', ''))
reason = []
results.append([id, profile])
print tabulate(results, headers=['ID', 'Profile'])
for item in results:
for entry in item:
print "{};".format(entry),
print
return
if __name__ == "__main__":
main()