cloud-governance 1.1.351__py3-none-any.whl → 1.1.352__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.
@@ -7,6 +7,7 @@ HOURS_IN_SECONDS = 3600
7
7
  HOURS_IN_DAY = 24
8
8
  HOURS_IN_MONTH = 720
9
9
  TOTAL_BYTES_IN_KIB = 1024
10
+ INSTANCE_START_PREFIX = 'i-'
10
11
 
11
12
  DATE_FORMAT = "%Y-%m-%d"
12
13
  DATE_TIME_FORMAT_T = "%Y-%m-%dT%h:%m"
@@ -1,6 +1,7 @@
1
1
  from datetime import datetime, timedelta
2
2
 
3
3
  from cloud_governance.common.logger.init_logger import logger
4
+ from cloud_governance.common.utils.configs import INSTANCE_START_PREFIX
4
5
  from cloud_governance.policy.policy_operations.aws.tag_non_cluster.non_cluster_operations import NonClusterOperations
5
6
 
6
7
 
@@ -36,7 +37,8 @@ class TagNonClusterResources(NonClusterOperations):
36
37
  @param tags:
37
38
  @return:
38
39
  """
39
- username = self.get_username(start_time=launch_time, resource_id=instance_id, resource_type='AWS::EC2::Instance', tags=tags)
40
+ username = self.get_username(start_time=launch_time, resource_id=instance_id,
41
+ resource_type='AWS::EC2::Instance', tags=tags)
40
42
  search_tags = []
41
43
  user_tags = []
42
44
  if not username:
@@ -73,8 +75,10 @@ class TagNonClusterResources(NonClusterOperations):
73
75
  if add_tags:
74
76
  if self.dry_run == 'no':
75
77
  try:
76
- self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags, resource_ids=[instance_id], tags=add_tags)
77
- logger.info(f'Added tags to instance: {instance_id} total: {len(add_tags)} tags: {add_tags}')
78
+ self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags,
79
+ resource_ids=[instance_id], tags=add_tags)
80
+ logger.info(
81
+ f'Added tags to instance: {instance_id} total: {len(add_tags)} tags: {add_tags}')
78
82
  except Exception as err:
79
83
  logger.info(err)
80
84
  instances_ids.append(instance_id)
@@ -94,7 +98,8 @@ class TagNonClusterResources(NonClusterOperations):
94
98
  volume_id = volume.get('VolumeId')
95
99
  tags = volume.get('Tags')
96
100
  if not self.validate_existing_tag(tags=tags):
97
- username = self.get_username(start_time=volume.get('CreateTime'), resource_id=volume_id, resource_type='AWS::EC2::Volume', tags=tags)
101
+ username = self.get_username(start_time=volume.get('CreateTime'), resource_id=volume_id,
102
+ resource_type='AWS::EC2::Volume', tags=tags)
98
103
  search_tags = []
99
104
  if not username:
100
105
  get_tags, username = self._get_tags_fom_attachments(attachments=volume.get('Attachments'))
@@ -120,8 +125,10 @@ class TagNonClusterResources(NonClusterOperations):
120
125
  if volume_tags:
121
126
  if self.dry_run == 'no':
122
127
  try:
123
- self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags, resource_ids=[volume_id], tags=volume_tags)
124
- logger.info(f'added tags to volume_id: {volume_id} total: {len(volume_tags)} tags: {volume_tags}')
128
+ self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags,
129
+ resource_ids=[volume_id], tags=volume_tags)
130
+ logger.info(
131
+ f'added tags to volume_id: {volume_id} total: {len(volume_tags)} tags: {volume_tags}')
125
132
  except Exception as err:
126
133
  logger.info(err)
127
134
  volume_ids.append(volume_id)
@@ -141,24 +148,33 @@ class TagNonClusterResources(NonClusterOperations):
141
148
  snapshot_id = snapshot.get('SnapshotId')
142
149
  tags = snapshot.get('Tags')
143
150
  if not self.validate_existing_tag(tags=tags):
144
- username = self.get_username(start_time=snapshot.get('StartTime'), resource_id=snapshot_id, resource_type='AWS::EC2::Snapshot', tags=tags)
151
+ username = self.get_username(start_time=snapshot.get('StartTime'), resource_id=snapshot_id,
152
+ resource_type='AWS::EC2::Snapshot', tags=tags)
145
153
  if 'vm_import_image' in username:
146
154
  start_time = snapshot.get('StartTime') + timedelta(seconds=5)
147
155
  end_time = start_time + timedelta(minutes=30)
148
- assume_username = self.get_username(start_time=start_time, resource_id=snapshot_id, resource_type='AWS::EC2::Snapshot', tags=tags, end_time=end_time)
156
+ assume_username = self.get_username(start_time=start_time, resource_id=snapshot_id,
157
+ resource_type='AWS::EC2::Snapshot', tags=tags,
158
+ end_time=end_time)
149
159
  if assume_username:
150
160
  username = assume_username
151
161
  search_tags = []
152
162
  if not username:
153
163
  if snapshot.get('Description') and 'Created' in snapshot.get('Description'):
154
- image_tags, username = self._get_tags_from_snapshot_description_images(description=snapshot.get('Description'))
164
+ image_tags, username = self._get_tags_from_snapshot_description_images(
165
+ description=snapshot.get('Description'))
155
166
  if not username:
156
- instance_id = snapshot.get('Description').split(" ")[2].split("(")[1][:-1]
157
- instances = self._get_instances_data(instance_id)
158
- if instances:
159
- for item in instances:
160
- if item.get('InstanceId') == instance_id:
161
- item_tags, username = self._get_tags_from_instance_item(instance_item=item)
167
+ if INSTANCE_START_PREFIX in snapshot.get('Description'):
168
+ try:
169
+ instance_id = snapshot.get('Description').split(" ")[2].split("(")[1][:-1]
170
+ instances = self._get_instances_data(instance_id)
171
+ if instances:
172
+ for item in instances:
173
+ if item.get('InstanceId') == instance_id:
174
+ item_tags, username = self._get_tags_from_instance_item(
175
+ instance_item=item)
176
+ except Exception as err:
177
+ logger.info(err)
162
178
  else:
163
179
  search_tags.extend(self._append_input_tags())
164
180
  if username:
@@ -179,8 +195,10 @@ class TagNonClusterResources(NonClusterOperations):
179
195
  if snapshot_tags:
180
196
  if self.dry_run == 'no':
181
197
  try:
182
- self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags, resource_ids=[snapshot_id], tags=snapshot_tags)
183
- logger.info(f'added tags to snapshots: {snapshot_id} total: {len(snapshot_tags)} tags: {snapshot_tags}')
198
+ self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags,
199
+ resource_ids=[snapshot_id], tags=snapshot_tags)
200
+ logger.info(
201
+ f'added tags to snapshots: {snapshot_id} total: {len(snapshot_tags)} tags: {snapshot_tags}')
184
202
  except Exception as err:
185
203
  logger.info(err)
186
204
  snapshot_ids.append(snapshot_id)
@@ -203,7 +221,8 @@ class TagNonClusterResources(NonClusterOperations):
203
221
  image_name = image.get('Name')
204
222
  start_time = datetime.fromisoformat(image.get('CreationDate')[:-1] + '+00:00')
205
223
  if not self.validate_existing_tag(tags=tags):
206
- username = self.get_username(start_time=start_time, resource_id=image_id, resource_type='AWS::EC2::Ami', tags=tags, resource_name=image_name)
224
+ username = self.get_username(start_time=start_time, resource_id=image_id, resource_type='AWS::EC2::Ami',
225
+ tags=tags, resource_name=image_name)
207
226
  search_tags = []
208
227
  search_tags.extend(self._append_input_tags())
209
228
  if username:
@@ -223,7 +242,8 @@ class TagNonClusterResources(NonClusterOperations):
223
242
  if image_tags:
224
243
  if self.dry_run == 'no':
225
244
  try:
226
- self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags, resource_ids=[image_id], tags=image_tags)
245
+ self.utils.tag_aws_resources(client_method=self.ec2_client.create_tags,
246
+ resource_ids=[image_id], tags=image_tags)
227
247
  logger.info(f'added tags to image: {image_id} total: {len(image_tags)} tags: {image_tags}')
228
248
  except Exception as err:
229
249
  logger.info(err)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: cloud-governance
3
- Version: 1.1.351
3
+ Version: 1.1.352
4
4
  Summary: Cloud Governance Tool
5
5
  Home-page: https://github.com/redhat-performance/cloud-governance
6
6
  Author: Red Hat
@@ -139,7 +139,7 @@ cloud_governance/common/tool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
139
139
  cloud_governance/common/tool/tool.py,sha256=EG4MGXzg6k6kLFff_pdghD--QBykgAZh0OPA7g8EPog,1241
140
140
  cloud_governance/common/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
141
141
  cloud_governance/common/utils/api_requests.py,sha256=WwkvVAhJKEpU0JWz0Df8yN2W7iN7Q7tieJM813_DZ9c,674
142
- cloud_governance/common/utils/configs.py,sha256=AinYkks4_Vkxyic8L8mk3tNg1m93proF5xZC5IJK8bc,1165
142
+ cloud_governance/common/utils/configs.py,sha256=8ry4UQT9s_GUivhrCdwS0vOWYN6OJIHDFzbVpi3BYpY,1194
143
143
  cloud_governance/common/utils/json_datetime_encoder.py,sha256=_-jzRTe0UqAKTn2E9qaU8SYIxHUoRA5ElWuVA0Y54Xw,338
144
144
  cloud_governance/common/utils/utils.py,sha256=ZUsi4ax2XhDIV-EQ5kJt5Ppd72kmm2psqcg1cNDZrvc,4349
145
145
  cloud_governance/main/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -220,7 +220,7 @@ cloud_governance/policy/policy_operations/aws/tag_non_cluster/__init__.py,sha256
220
220
  cloud_governance/policy/policy_operations/aws/tag_non_cluster/non_cluster_operations.py,sha256=PUWS0SE7T56BejBa3FRUK-txq70gVHztNAj1JmB-Ra0,9497
221
221
  cloud_governance/policy/policy_operations/aws/tag_non_cluster/remove_non_cluster_tags.py,sha256=d-RKpWSaZi2ALQaA9_MwqxHwzbSpsdyjQTBacJVoOLw,8362
222
222
  cloud_governance/policy/policy_operations/aws/tag_non_cluster/run_tag_non_cluster_resources.py,sha256=KG0B0sjaI8SI7ZUf13Aw6kOgUfX7u83yazj9lsraPJU,2612
223
- cloud_governance/policy/policy_operations/aws/tag_non_cluster/tag_non_cluster_resources.py,sha256=Fvcu5uB3pvQEol8fLUbYWEQnrz_l3KuDdxl0KM8f0EI,12941
223
+ cloud_governance/policy/policy_operations/aws/tag_non_cluster/tag_non_cluster_resources.py,sha256=yevICSIFuzinE8jltZOX2DLDxBL2ZH7Eg82nQQuQeuI,13994
224
224
  cloud_governance/policy/policy_operations/aws/tag_non_cluster/update_na_tag_resources.py,sha256=HkDNAKqRXmdNTInnww36kyxEg_PHpf0-2G5TmUG3ZNE,6139
225
225
  cloud_governance/policy/policy_operations/aws/tag_user/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
226
226
  cloud_governance/policy/policy_operations/aws/tag_user/iam_user_tags.py,sha256=s9lmZPQ2lUrbg0AIvQvoTSQMZhFjLduMZO3befZ7u6Y,3389
@@ -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.351.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
267
- cloud_governance-1.1.351.dist-info/METADATA,sha256=XIDGqG496xIcJlP-7UvcYgbxppoCr6Bo-z65FjiUemE,11342
268
- cloud_governance-1.1.351.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
269
- cloud_governance-1.1.351.dist-info/top_level.txt,sha256=jfB1fgj7jvx3YZkZA4G6hFeS1RHO7J7XtnbjuMNMRww,17
270
- cloud_governance-1.1.351.dist-info/RECORD,,
266
+ cloud_governance-1.1.352.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
267
+ cloud_governance-1.1.352.dist-info/METADATA,sha256=LHvDw6tMyC_ptw4Fq3tSEwI8YW6EEwuYFOANMwlwXR4,11342
268
+ cloud_governance-1.1.352.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
269
+ cloud_governance-1.1.352.dist-info/top_level.txt,sha256=jfB1fgj7jvx3YZkZA4G6hFeS1RHO7J7XtnbjuMNMRww,17
270
+ cloud_governance-1.1.352.dist-info/RECORD,,