forked from hao-ua/aws_inventory
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_EC.py
More file actions
56 lines (48 loc) · 2.12 KB
/
data_EC.py
File metadata and controls
56 lines (48 loc) · 2.12 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
48
49
50
51
52
53
54
55
56
import boto.elasticache
class Data(object):
def __init__(self, credentials, items):
self.Name = 'EC'
self.Priority = 6
self.show = True
self.HeaderNames = ['Name', 'Endpoint', 'Status', 'Node type', 'Maintenance', 'Engine']
self.HeaderWidths = ['2', '6', '1', '2', '3', '2']
self.HeaderKeys = ['name', 'endpoint', 'status', 'type', 'maintenance', 'engine']
self.credentials = credentials
self.Items = items
self.skipRegions = []
@staticmethod
def result_dict(item):
res = dict()
res['name'] = item['CacheClusterId']
res['engine'] = item['Engine']
if item['ConfigurationEndpoint'] is None:
res['endpoint'] = ""
else:
res['endpoint'] = ''.join([item['ConfigurationEndpoint']['Address'], ':',
str(item['ConfigurationEndpoint']['Port'])])
res['status'] = item['CacheClusterStatus']
res['type'] = item['CacheNodeType']
res['placement'] = item['PreferredAvailabilityZone']
res['maintenance'] = item['PreferredMaintenanceWindow']
return res
def get_all_items(self, aws_key, aws_secret):
result = {}
regions = boto.elasticache.regions()
for region in regions:
if region.name in self.skipRegions:
continue
conn = region.connect(aws_access_key_id=aws_key, aws_secret_access_key=aws_secret)
cache_clusters = conn.describe_cache_clusters()['DescribeCacheClustersResponse'] \
['DescribeCacheClustersResult']['CacheClusters']
for cluster in cache_clusters:
cluster_dict = self.result_dict(cluster)
if cluster_dict['placement'] in result:
result[cluster_dict['placement']].append(cluster_dict)
else:
result[cluster_dict['placement']] = [cluster_dict]
return result
def get_data(self):
ecs = {}
for credential in self.credentials:
ecs[credential[2]] = self.get_all_items(credential[0], credential[1])
return ecs