forked from hao-ua/aws_inventory
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_RDS.py
More file actions
47 lines (40 loc) · 1.73 KB
/
data_RDS.py
File metadata and controls
47 lines (40 loc) · 1.73 KB
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
import boto
import boto.rds
import boto.ec2
class Data(object):
def __init__(self, credentials, items):
self.Name = 'RDS'
self.Priority = 5
self.show = True
self.HeaderNames = ['Name', 'Endpoint', 'Allocated storage', 'Instance class', 'Status']
self.HeaderWidths = ['2', '6', '2', '2', '2']
self.HeaderKeys = ['name', 'endpoint', 'allocated_storage', 'instance_class', 'status']
self.credentials = credentials
self.Items = items
self.skipRegions = []
@staticmethod
def result_dict(db_instance):
res = dict()
res['name'] = db_instance.id
res['endpoint'] = ':'.join([db_instance.endpoint[0], str(db_instance.endpoint[1])])
res['allocated_storage'] = ''.join([str(db_instance.allocated_storage), 'Gb'])
res['instance_class'] = db_instance.instance_class
res['status'] = db_instance.status
return res
def get_all_items(self, aws_key, aws_secret):
result = dict()
regions = boto.ec2.regions(aws_access_key_id=aws_key, aws_secret_access_key=aws_secret)
for region in regions:
if region.name in self.skipRegions:
continue
conn = boto.rds.connect_to_region(region.name, aws_access_key_id=aws_key, aws_secret_access_key=aws_secret)
db_instances = conn.get_all_dbinstances()
result[region.name] = []
for db_instance in db_instances:
result[region.name].append(self.result_dict(db_instance))
return result
def get_data(self):
rdses = dict()
for credential in self.credentials:
rdses[credential[2]] = self.get_all_items(credential[0], credential[1])
return rdses