Skip to content

Commit

Permalink
Added some hot fixes (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma authored Oct 9, 2023
1 parent 9e2c01c commit c9f0671
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion cloud_governance/common/clouds/aws/ec2/ec2_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c9f0671

Please sign in to comment.