-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2_details.py
110 lines (86 loc) · 2.81 KB
/
ec2_details.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from config import conf
class ec2_details:
"""
Main class for boto3 client for ec2
"""
def __init__(self,session_client):
self.session = session_client
self.connection = self.session.client('ec2')
self.region_list = []
# fetching all ec2 regions from describe_regions api call (this is only for ec2)
self.region_list = [i['RegionName'] for i in self.connection.describe_regions()['Regions']]
def get_instances(self):
"""
Getting all instance details for every region
"""
self.clients = []
self.clients.append(self.connection)
self.instances_list = []
[self.instances_list.append(i.describe_instances()) for i in self.clients]
return self.instances_list
def get_volumes(self):
"""
fetching volume details for running instance
"""
response = self.connection.describe_volumes()
return response['Volumes']
def get_snapshots(self):
"""
Fetching snapshot details from ec2
"""
response = self.connection.describe_snapshots()
return response['Snapshots']
def get_amis(self):
"""
Fetching ami details from ec2
"""
response = self.connection.describe_images()
return response['Images']
class instance_details:
"""
Instance details class
"""
def __init__(self,instance):
self.instance = instance
self.tag = ''
if 'Tags' in self.instance['Instances'][0].keys():
for t in self.instance['Instances'][0]['Tags']:
if t['Key'] == conf['tag']:
self.tag = t['Value']
self.id = self.instance['Instances'][0]['InstanceId']
class volume_details:
"""
Volume details class
"""
def __init__(self,instance):
self.instance = instance
self.project = ''
self.id = self.instance['VolumeId']
if 'Tags' in instance.keys():
for t in self.instance['Tags']:
if t['Key'] == conf['tag']:
self.tag = t['Value']
class snapshot_details:
"""
Snapshot details class
"""
def __init__(self,instance):
self.instance = instance
self.project = ''
self.id = self.instance['SnapshotId']
if 'Tags' in instance.keys():
for t in self.instance['Tags']:
if t['Key'] == conf['tag']:
self.tag = t['Value']
class ami_details:
"""
Ami details class
"""
def __init__(self,instance):
self.instance = instance
self.project = ''
self.id = self.instance['ImageId']
if 'Tags' in instance.keys():
for t in self.instance['Tags']:
if t['Key'] == conf['tag']:
self.tag = t['Value']