cloud-governance 1.1.354__py3-none-any.whl → 1.1.356__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.
@@ -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 NonClusterZombiePolicy
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, delete_instance_days=self.DELETE_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 = self._ec2_client.describe_instances(Filters=[{'Name': 'instance-state-name', 'Values': ['stopped']}])['Reservations']
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', resource_hours=(self.DAILY_HOURS * days))
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'), resource_type='ec2', resource_hours=(self.DAILY_HOURS * (days-self.FIRST_MAIL_NOTIFICATION_INSTANCE_DAYS)))
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, resource_id=instance_id, days=days, ec2_type=resource.get("InstanceType"), instance_id=instance_id, message_type='notification', stop_cost=stop_cost, delta_cost=delta_cost)
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'), resource_type='ec2', resource_hours=(self.DAILY_HOURS * (self.DAYS_TO_NOTIFY_ADMINS-self.SECOND_MAIL_NOTIFICATION_INSTANCE_DAYS)))
66
- self.__trigger_mail(tags=resource.get('Tags'), stopped_time=stopped_time, resource_id=instance_id,
67
- days=days, ec2_type=resource.get("InstanceType"), instance_id=instance_id, admins=self._admins,
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
- 'LaunchTime': str(resource.get('LaunchTime')),
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 = '', ec2_type: str = '', instance_id: str = '', **kwargs):
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, tag_name='User'), self._get_tag_name_from_tags(tags=tags, tag_name='Name')
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, image_id=image_id, delete_instance_days=self.DELETE_INSTANCE_DAYS, instance_name=instance_name, resource_id=resource_id, stopped_time=stopped_time, ec2_type=ec2_type, extra_purse=kwargs.get('stop_cost'))
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, resource_id=instance_id, message_type=kwargs.get('message_type'), extra_purse=kwargs.get('delta_cost', 0))
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)
@@ -51,6 +51,8 @@ class IBMCostReport:
51
51
  hardware_tags = self.collect_tags_from_machines(
52
52
  tags=self.classic_operations.get_hardware_tags(hardware_id=str(hardware.get('id'))))
53
53
  hardware_tags['fqdn'] = hardware.get('fullyQualifiedDomainName').lower()
54
+ if 'budget' not in hardware_tags:
55
+ hardware_tags['budget'] = self.__environment_variables_dict.get('account')
54
56
  collect_machines_data[hardware_tags['fqdn']] = hardware_tags
55
57
  return collect_machines_data
56
58
 
@@ -86,7 +88,8 @@ class IBMCostReport:
86
88
  if fqdn not in collect_machines_data:
87
89
  user = [user for user in users if user in fqdn]
88
90
  if user:
89
- user_tags = self.ibm_account.get_user_tags_from_gsheet(username=f'{user[0]}@redhat.com', user_email='yes')
91
+ user_tags = self.ibm_account.get_user_tags_from_gsheet(username=f'{user[0]}@redhat.com',
92
+ user_email='yes')
90
93
  invoice_data[fqdn].update(self.collect_tags_from_machines(user_tags))
91
94
  return invoice_data
92
95
 
@@ -112,15 +115,17 @@ class IBMCostReport:
112
115
  collect_machines_data = self.get_hardware_data()
113
116
  collect_machines_data.update(self.get_virtual_machine_data())
114
117
  invoice_data = self.get_invoice_data(collect_machines_data=collect_machines_data)
115
- cost_invoice_resource_data = self.concatenate_dictionaries(resource_data=collect_machines_data, invoice_data=invoice_data)
118
+ cost_invoice_resource_data = self.concatenate_dictionaries(resource_data=collect_machines_data,
119
+ invoice_data=invoice_data)
116
120
  for tag_name in self.owned_tags:
117
121
  cost_list_items = []
118
122
  for _, data in cost_invoice_resource_data.items():
119
- if data[tag_name] != 0 or tag_name == 'budget':
123
+ if data.get(tag_name) != 0 or tag_name == 'budget':
120
124
  cost_list_items.append({
121
125
  tag_name.capitalize(): data[tag_name],
122
126
  'Cost': data['cost'],
123
127
  'Budget': self._elastic_upload.account
124
128
  })
125
- self._elastic_upload.es_upload_data(items=cost_list_items, es_index=f'{self._elastic_upload.es_index}-{tag_name.lower()}')
129
+ self._elastic_upload.es_upload_data(items=cost_list_items,
130
+ es_index=f'{self._elastic_upload.es_index}-{tag_name.lower()}')
126
131
  return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloud-governance
3
- Version: 1.1.354
3
+ Version: 1.1.356
4
4
  Summary: Cloud Governance Tool
5
5
  Home-page: https://github.com/redhat-performance/cloud-governance
6
6
  Author: Red Hat
@@ -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=21Ju0XZt67A-u_nTUXQjgy_8wUIvZ6N5OUkKS8oP810,8494
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
@@ -200,7 +200,7 @@ cloud_governance/policy/ibm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
200
200
  cloud_governance/policy/ibm/cost_billing_reports.py,sha256=3qQlgugtBQGw_W3PhrsQCehi4r4o1QPr6G50ZWGATnE,4118
201
201
  cloud_governance/policy/ibm/cost_usage_reports.py,sha256=UoiGugo9wCtoEKBWd-a4hbkbFhfWOf5BgM8Z6VkWnNU,2298
202
202
  cloud_governance/policy/ibm/ibm_cost_over_usage.py,sha256=C9ZkpMjRao9FQ2iZSXFdXqGxctBZVoLe-JXEupqIJ10,3595
203
- cloud_governance/policy/ibm/ibm_cost_report.py,sha256=3DbC_Os_vy-V4dD7i63JvWvd25dXgZa7oJHQIHETrec,5385
203
+ cloud_governance/policy/ibm/ibm_cost_report.py,sha256=xv-TX4eDgnTt5EM_iCLrUwj5hXRmHrsCfE6bs-bSlIo,5716
204
204
  cloud_governance/policy/ibm/tag_baremetal.py,sha256=7vVh3t4mqs_RDEzSwUS1E2xQzHnwJYPs3lGn5V7d3RU,5329
205
205
  cloud_governance/policy/ibm/tag_resources.py,sha256=g0ypZuKsQrJxscWDmcCdXHm9AS2fpMWsqpMCorF_Tdc,6324
206
206
  cloud_governance/policy/ibm/tag_vm.py,sha256=G3QLYwuB2cWSHAsoR40BHVBV5nmGVcVzLtJLmM3MenA,4836
@@ -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.354.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
267
- cloud_governance-1.1.354.dist-info/METADATA,sha256=nG7sgx5aOcgWvLHt4NVvtPRZyARdCfXX97SJ81k4KfU,11364
268
- cloud_governance-1.1.354.dist-info/WHEEL,sha256=tTnHoFhvKQHCh4jz3yCn0WPTYIy7wXx3CJtJ7SJGV7c,91
269
- cloud_governance-1.1.354.dist-info/top_level.txt,sha256=jfB1fgj7jvx3YZkZA4G6hFeS1RHO7J7XtnbjuMNMRww,17
270
- cloud_governance-1.1.354.dist-info/RECORD,,
266
+ cloud_governance-1.1.356.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
267
+ cloud_governance-1.1.356.dist-info/METADATA,sha256=mNvoFNdQ_M3Q5wLHAUhE4wmpfqZ_voKMcz_0AeMkiJw,11364
268
+ cloud_governance-1.1.356.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
269
+ cloud_governance-1.1.356.dist-info/top_level.txt,sha256=jfB1fgj7jvx3YZkZA4G6hFeS1RHO7J7XtnbjuMNMRww,17
270
+ cloud_governance-1.1.356.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.1)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5