cloud-governance 1.1.353__py3-none-any.whl → 1.1.355__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cloud_governance/common/clouds/aws/s3/s3_operations.py +3 -2
- cloud_governance/policy/aws/ec2_stop.py +38 -14
- {cloud_governance-1.1.353.dist-info → cloud_governance-1.1.355.dist-info}/METADATA +3 -2
- {cloud_governance-1.1.353.dist-info → cloud_governance-1.1.355.dist-info}/RECORD +7 -7
- {cloud_governance-1.1.353.dist-info → cloud_governance-1.1.355.dist-info}/WHEEL +1 -1
- {cloud_governance-1.1.353.dist-info → cloud_governance-1.1.355.dist-info/licenses}/LICENSE +0 -0
- {cloud_governance-1.1.353.dist-info → cloud_governance-1.1.355.dist-info}/top_level.txt +0 -0
|
@@ -27,7 +27,7 @@ class S3Operations:
|
|
|
27
27
|
self.__report_file_name = report_file_name
|
|
28
28
|
self.__resource_file_name = resource_file_name
|
|
29
29
|
self.__report_file_full_path = os.path.join(os.path.dirname(__file__), self.__report_file_name)
|
|
30
|
-
self.__resources_file_full_path = os.path.join(
|
|
30
|
+
self.__resources_file_full_path = os.path.join('/tmp', self.__resource_file_name)
|
|
31
31
|
if bucket and logs_bucket_key:
|
|
32
32
|
self.__bucket, self.__logs_bucket_key = bucket, logs_bucket_key
|
|
33
33
|
|
|
@@ -383,7 +383,8 @@ class S3Operations:
|
|
|
383
383
|
:return:
|
|
384
384
|
"""
|
|
385
385
|
try:
|
|
386
|
-
return self.__s3_client.get_bucket_location(Bucket=bucket_name, **kwargs).get('LocationConstraint',
|
|
386
|
+
return self.__s3_client.get_bucket_location(Bucket=bucket_name, **kwargs).get('LocationConstraint',
|
|
387
|
+
self.__region)
|
|
387
388
|
except Exception as err:
|
|
388
389
|
logger.error(err)
|
|
389
390
|
return self.__region
|
|
@@ -3,7 +3,8 @@ import operator
|
|
|
3
3
|
|
|
4
4
|
from cloud_governance.common.clouds.aws.cloudtrail.cloudtrail_operations import CloudTrailOperations
|
|
5
5
|
from cloud_governance.common.logger.init_logger import logger
|
|
6
|
-
from cloud_governance.policy.policy_operations.aws.zombie_non_cluster.run_zombie_non_cluster_policies import
|
|
6
|
+
from cloud_governance.policy.policy_operations.aws.zombie_non_cluster.run_zombie_non_cluster_policies import \
|
|
7
|
+
NonClusterZombiePolicy
|
|
7
8
|
from operator import ge
|
|
8
9
|
|
|
9
10
|
|
|
@@ -28,14 +29,17 @@ class EC2Stop(NonClusterZombiePolicy):
|
|
|
28
29
|
This method list all stopped instances for more than 30 days and terminate if dry_run no
|
|
29
30
|
@return:
|
|
30
31
|
"""
|
|
31
|
-
return self.__fetch_stop_instance(sign=ge, instance_days=self.FIRST_MAIL_NOTIFICATION_INSTANCE_DAYS,
|
|
32
|
+
return self.__fetch_stop_instance(sign=ge, instance_days=self.FIRST_MAIL_NOTIFICATION_INSTANCE_DAYS,
|
|
33
|
+
delete_instance_days=self.DELETE_INSTANCE_DAYS)
|
|
32
34
|
|
|
33
35
|
def __fetch_stop_instance(self, instance_days: int, delete_instance_days: int, sign: operator = ge):
|
|
34
36
|
"""
|
|
35
37
|
This method list all stopped instances for more than 30 days and terminate if dry_run no
|
|
36
38
|
@return:
|
|
37
39
|
"""
|
|
38
|
-
instances =
|
|
40
|
+
instances = \
|
|
41
|
+
self._ec2_client.describe_instances(Filters=[{'Name': 'instance-state-name', 'Values': ['stopped']}])[
|
|
42
|
+
'Reservations']
|
|
39
43
|
stopped_instances = []
|
|
40
44
|
stopped_instance_tags = {}
|
|
41
45
|
ec2_types = {}
|
|
@@ -51,20 +55,30 @@ class EC2Stop(NonClusterZombiePolicy):
|
|
|
51
55
|
stopped_time = datetime.datetime.now()
|
|
52
56
|
days = self._calculate_days(create_date=stopped_time)
|
|
53
57
|
user = self._get_tag_name_from_tags(tags=resource.get('Tags'), tag_name='User')
|
|
54
|
-
stop_cost = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'), resource_type='ec2',
|
|
58
|
+
stop_cost = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'), resource_type='ec2',
|
|
59
|
+
resource_hours=(self.DAILY_HOURS * days))
|
|
55
60
|
if days in (instance_days, self.SECOND_MAIL_NOTIFICATION_INSTANCE_DAYS):
|
|
56
61
|
if days == self.SECOND_MAIL_NOTIFICATION_INSTANCE_DAYS:
|
|
57
|
-
delta_cost = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'),
|
|
62
|
+
delta_cost = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'),
|
|
63
|
+
resource_type='ec2', resource_hours=(
|
|
64
|
+
self.DAILY_HOURS * (days - self.FIRST_MAIL_NOTIFICATION_INSTANCE_DAYS)))
|
|
58
65
|
else:
|
|
59
66
|
delta_cost = stop_cost
|
|
60
67
|
if user:
|
|
61
|
-
self.__trigger_mail(tags=resource.get('Tags'), stopped_time=stopped_time,
|
|
68
|
+
self.__trigger_mail(tags=resource.get('Tags'), stopped_time=stopped_time,
|
|
69
|
+
resource_id=instance_id, days=days,
|
|
70
|
+
ec2_type=resource.get("InstanceType"), instance_id=instance_id,
|
|
71
|
+
message_type='notification', stop_cost=stop_cost, delta_cost=delta_cost)
|
|
62
72
|
else:
|
|
63
73
|
logger.info('User is missing')
|
|
64
74
|
if days == self.DAYS_TO_NOTIFY_ADMINS:
|
|
65
|
-
delta_charge = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'),
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
delta_charge = self.get_ebs_cost(resource=resource.get('BlockDeviceMappings'),
|
|
76
|
+
resource_type='ec2', resource_hours=(self.DAILY_HOURS * (
|
|
77
|
+
self.DAYS_TO_NOTIFY_ADMINS - self.SECOND_MAIL_NOTIFICATION_INSTANCE_DAYS)))
|
|
78
|
+
self.__trigger_mail(tags=resource.get('Tags'), stopped_time=stopped_time,
|
|
79
|
+
resource_id=instance_id,
|
|
80
|
+
days=days, ec2_type=resource.get("InstanceType"), instance_id=instance_id,
|
|
81
|
+
admins=self._admins,
|
|
68
82
|
message_type='notify-admin', stop_cost=stop_cost, delta_charge=delta_charge)
|
|
69
83
|
if sign(days, instance_days):
|
|
70
84
|
if days >= delete_instance_days:
|
|
@@ -78,7 +92,7 @@ class EC2Stop(NonClusterZombiePolicy):
|
|
|
78
92
|
'StoppedDate': str(resource.get('UsageOperationUpdateTime')),
|
|
79
93
|
'Name': self._get_tag_name_from_tags(tags=resource.get('Tags'), tag_name='Name'),
|
|
80
94
|
'User': self._get_tag_name_from_tags(tags=resource.get('Tags'), tag_name='User'),
|
|
81
|
-
'
|
|
95
|
+
'ResourceLaunchTime': str(resource.get('LaunchTime')),
|
|
82
96
|
'Policy': self._get_tag_name_from_tags(tags=resource.get('Tags'), tag_name='Policy')})
|
|
83
97
|
if self._dry_run == "no":
|
|
84
98
|
for instance_id, tags in stopped_instance_tags.items():
|
|
@@ -99,7 +113,8 @@ class EC2Stop(NonClusterZombiePolicy):
|
|
|
99
113
|
# logger.info(err)
|
|
100
114
|
return stopped_instances
|
|
101
115
|
|
|
102
|
-
def __trigger_mail(self, tags: list, stopped_time: str, resource_id: str, days: int, image_id: str = '',
|
|
116
|
+
def __trigger_mail(self, tags: list, stopped_time: str, resource_id: str, days: int, image_id: str = '',
|
|
117
|
+
ec2_type: str = '', instance_id: str = '', **kwargs):
|
|
103
118
|
"""
|
|
104
119
|
This method send triggering mail
|
|
105
120
|
@param tags:
|
|
@@ -110,16 +125,25 @@ class EC2Stop(NonClusterZombiePolicy):
|
|
|
110
125
|
"""
|
|
111
126
|
try:
|
|
112
127
|
special_user_mails = self._literal_eval(self._special_user_mails)
|
|
113
|
-
user, instance_name = self._get_tag_name_from_tags(tags=tags,
|
|
128
|
+
user, instance_name = self._get_tag_name_from_tags(tags=tags,
|
|
129
|
+
tag_name='User'), self._get_tag_name_from_tags(tags=tags,
|
|
130
|
+
tag_name='Name')
|
|
114
131
|
to = user if user not in special_user_mails else special_user_mails[user]
|
|
115
132
|
ldap_data = self._ldap.get_user_details(user_name=to)
|
|
116
133
|
cc = []
|
|
117
|
-
subject, body = self._mail_description.ec2_stop(name=ldap_data.get('displayName'), days=days,
|
|
134
|
+
subject, body = self._mail_description.ec2_stop(name=ldap_data.get('displayName'), days=days,
|
|
135
|
+
image_id=image_id,
|
|
136
|
+
delete_instance_days=self.DELETE_INSTANCE_DAYS,
|
|
137
|
+
instance_name=instance_name, resource_id=resource_id,
|
|
138
|
+
stopped_time=stopped_time, ec2_type=ec2_type,
|
|
139
|
+
extra_purse=kwargs.get('stop_cost'))
|
|
118
140
|
if not kwargs.get('admins'):
|
|
119
141
|
kwargs['admins'] = to
|
|
120
142
|
cc = [self._account_admin, f'{ldap_data.get("managerId")}@redhat.com']
|
|
121
143
|
else:
|
|
122
144
|
kwargs['admins'].append(f'{ldap_data.get("managerId")}@redhat.com')
|
|
123
|
-
self._mail.send_email_postfix(to=kwargs.get('admins'), content=body, subject=subject, cc=cc,
|
|
145
|
+
self._mail.send_email_postfix(to=kwargs.get('admins'), content=body, subject=subject, cc=cc,
|
|
146
|
+
resource_id=instance_id, message_type=kwargs.get('message_type'),
|
|
147
|
+
extra_purse=kwargs.get('delta_cost', 0))
|
|
124
148
|
except Exception as err:
|
|
125
149
|
logger.info(err)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-governance
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.355
|
|
4
4
|
Summary: Cloud Governance Tool
|
|
5
5
|
Home-page: https://github.com/redhat-performance/cloud-governance
|
|
6
6
|
Author: Red Hat
|
|
@@ -62,6 +62,7 @@ Dynamic: description
|
|
|
62
62
|
Dynamic: description-content-type
|
|
63
63
|
Dynamic: home-page
|
|
64
64
|
Dynamic: license
|
|
65
|
+
Dynamic: license-file
|
|
65
66
|
Dynamic: requires-dist
|
|
66
67
|
Dynamic: summary
|
|
67
68
|
|
|
@@ -62,7 +62,7 @@ cloud_governance/common/clouds/aws/resource_explorer/resource_explorer_operation
|
|
|
62
62
|
cloud_governance/common/clouds/aws/resource_tagging_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
63
63
|
cloud_governance/common/clouds/aws/resource_tagging_api/resource_tag_api_operations.py,sha256=KYSYpEwLsjT7K7E8cu_oAzzWrMdlyqlPvzuJQ2Xuzc0,2193
|
|
64
64
|
cloud_governance/common/clouds/aws/s3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
65
|
-
cloud_governance/common/clouds/aws/s3/s3_operations.py,sha256=
|
|
65
|
+
cloud_governance/common/clouds/aws/s3/s3_operations.py,sha256=vLSooboPiIVzINhdDXgu_0UQwoecoPLfwt_UugdbV6c,14407
|
|
66
66
|
cloud_governance/common/clouds/aws/savingsplan/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
67
|
cloud_governance/common/clouds/aws/savingsplan/savings_plans_operations.py,sha256=3C7QBnuqG4sjh3ZApamNWdlNO2f3uoSvuOf2FQbci_w,6238
|
|
68
68
|
cloud_governance/common/clouds/aws/sts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -158,7 +158,7 @@ cloud_governance/policy/aws/cost_explorer.py,sha256=45GpfojLXXwwYSXREhPOA1ATgy1E
|
|
|
158
158
|
cloud_governance/policy/aws/cost_explorer_payer_billings.py,sha256=EuTry807RRw0SXNkyCmbK9CGuO1zT7fvv6odIy9338k,18731
|
|
159
159
|
cloud_governance/policy/aws/cost_over_usage.py,sha256=Jhv9VNpgIK1cEGJS6CFitkxwM3o8AUf98N1sRTUL09w,5351
|
|
160
160
|
cloud_governance/policy/aws/ebs_in_use.py,sha256=7vGV2qobV14rzC7tJnJiafC3oAhnY_TTvd53oEtaN4Q,616
|
|
161
|
-
cloud_governance/policy/aws/ec2_stop.py,sha256=
|
|
161
|
+
cloud_governance/policy/aws/ec2_stop.py,sha256=FXQNkHmiMCEw6Pz6CalIIVYFRsV24RT5TewqFazyP8M,9641
|
|
162
162
|
cloud_governance/policy/aws/empty_roles.py,sha256=EhsepFRbjU82PjJQ1hADqBM_RO1Ukr-Q4DZAz3bM4ho,3155
|
|
163
163
|
cloud_governance/policy/aws/ip_unattached.py,sha256=OnHlTIKSgyxwdAgU9jBApdvDQpzHgECjSodN6KoXWqU,3176
|
|
164
164
|
cloud_governance/policy/aws/monthly_report.py,sha256=jxdObuFEWPobRFtVKgo-sMT4gmMC_KS9gkPVF8ZqjpY,6722
|
|
@@ -263,8 +263,8 @@ cloud_governance/policy/policy_runners/elasticsearch/__init__.py,sha256=47DEQpj8
|
|
|
263
263
|
cloud_governance/policy/policy_runners/elasticsearch/upload_elastic_search.py,sha256=pOwUJWXjJbyTy8iv3Ap8xJGnqQe-5lZgoR8-vGfAVos,1881
|
|
264
264
|
cloud_governance/policy/policy_runners/ibm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
265
265
|
cloud_governance/policy/policy_runners/ibm/policy_runner.py,sha256=V0E_f7F3hXit0aSq4BlfX1Jd4vjR2NEvOWsJ5upvZ4o,1302
|
|
266
|
-
cloud_governance-1.1.
|
|
267
|
-
cloud_governance-1.1.
|
|
268
|
-
cloud_governance-1.1.
|
|
269
|
-
cloud_governance-1.1.
|
|
270
|
-
cloud_governance-1.1.
|
|
266
|
+
cloud_governance-1.1.355.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
267
|
+
cloud_governance-1.1.355.dist-info/METADATA,sha256=-gNmzHnA6GTcCPgADOqlBJX8SFkBeX_5C9tpkFUEBYE,11364
|
|
268
|
+
cloud_governance-1.1.355.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
|
269
|
+
cloud_governance-1.1.355.dist-info/top_level.txt,sha256=jfB1fgj7jvx3YZkZA4G6hFeS1RHO7J7XtnbjuMNMRww,17
|
|
270
|
+
cloud_governance-1.1.355.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|