From c9f0671736b0a7ed2f1f160c1d355ab793660866 Mon Sep 17 00:00:00 2001 From: Thirumalesh Aaraveti <97395760+athiruma@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:05:36 +0530 Subject: [PATCH] Added some hot fixes (#683) --- .../clouds/aws/ec2/monitor_cro_instances.py | 2 +- .../clouds/aws/ec2/tag_cro_instances.py | 3 ++- .../common/abstract_monitor_tickets.py | 2 ++ cloud_governance/common/clouds/aws/ec2/ec2_operations.py | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/monitor_cro_instances.py b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/monitor_cro_instances.py index 00d820ec..e63c2577 100644 --- a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/monitor_cro_instances.py +++ b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/monitor_cro_instances.py @@ -39,9 +39,9 @@ def __monitor_instances(self): .append(f"{self.__ec2_operations.get_tag_value_from_tags(tag_name='Name', tags=tags)}: " f"{resource.get('InstanceId')}: {resource.get('InstanceLifecycle', 'ondemand')}: " f"{resource.get('InstanceType')}: {'rosa' if rosa else 'self'}") - cluster_tickets.setdefault(ticket_id, {}).setdefault(cluster_key, {}).setdefault('region_name', []).append(self.__region_name) cluster_tickets.setdefault(ticket_id, {}).setdefault(cluster_key, {}). \ update({ + 'region_name': self.__region_name, 'ticket_id': ticket_id, 'user_cro': self.__ec2_operations.get_tag_value_from_tags(tag_name='UserCRO', tags=tags), 'user': self.__ec2_operations.get_tag_value_from_tags(tag_name='User', tags=tags), diff --git a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/tag_cro_instances.py b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/tag_cro_instances.py index e923e128..ac9ee9d9 100644 --- a/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/tag_cro_instances.py +++ b/cloud_governance/cloud_resource_orchestration/clouds/aws/ec2/tag_cro_instances.py @@ -123,7 +123,8 @@ def __tag_instances(self): ticket_id = self.__ec2_operations.get_tag_value_from_tags(tags=resource.get('Tags'), tag_name=self.__cro_resource_tag_name) if resource.get('Tags') else None if ticket_id: duration = self.__ec2_operations.get_tag_value_from_tags(tags=resource.get('Tags'), tag_name='Duration') - if not duration: + cost_estimation = self.__ec2_operations.get_tag_value_from_tags(tags=resource.get('Tags'), tag_name='EstimatedCost') + if not duration or not cost_estimation: volume_ids = self.__get_instance_volumes(resource.get('BlockDeviceMappings')) if self.__tag_ticket_id_attach_instance(ticket_id=ticket_id, instance_id=instance_id, volume_ids=volume_ids, user=user): ticket_id_instances.setdefault(ticket_id, []).append(instance_id) diff --git a/cloud_governance/cloud_resource_orchestration/common/abstract_monitor_tickets.py b/cloud_governance/cloud_resource_orchestration/common/abstract_monitor_tickets.py index 402239d3..83553293 100644 --- a/cloud_governance/cloud_resource_orchestration/common/abstract_monitor_tickets.py +++ b/cloud_governance/cloud_resource_orchestration/common/abstract_monitor_tickets.py @@ -229,6 +229,8 @@ def _monitor_in_progress_tickets(self): if source_data: ticket_id = source_data.get('ticket_id') region_name = source_data.get('region_name', '') + if type(region_name) is list: + region_name = list(set(region_name))[0] budget = int(source_data.get('estimated_cost', 0)) duration = int(source_data.get('duration', 0)) used_budget = int(source_data.get('actual_cost', 0)) diff --git a/cloud_governance/common/clouds/aws/ec2/ec2_operations.py b/cloud_governance/common/clouds/aws/ec2/ec2_operations.py index 735e7459..ab704ba0 100644 --- a/cloud_governance/common/clouds/aws/ec2/ec2_operations.py +++ b/cloud_governance/common/clouds/aws/ec2/ec2_operations.py @@ -533,7 +533,7 @@ def get_tag_value_from_tags(self, tags: list, tag_name: str, cast_type: str = 's if key == tag_name.lower(): if cast_type: if cast_type == 'int': - return int(tag.get('Value').strip()) + return int(tag.get('Value').split()[0].strip()) elif cast_type == 'float': return float(tag.get('Value').strip()) else: