Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format the ec2/ volume data #697

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,37 @@ def _organise_instance_data(self, resources: list):
organize_data = []
if 'ec2' in self._policy:
for instance in resources:
instance['LaunchTime'] = instance['LaunchTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
skip_policy = self._ec2_operations.get_tag_value_from_tags(tags=instance.get('Tags', []), tag_name='Policy')
if not skip_policy:
skip_policy = self._ec2_operations.get_tag_value_from_tags(tags=instance.get('Tags', []), tag_name='Skip')
instance_data = {
'ResourceId': instance.get('InstanceId'), 'InstanceId': instance.get('InstanceId'),
'User': self._ec2_operations.get_tag_value_from_tags(tags=instance.get('Tags', []), tag_name='User'),
'Policy': skip_policy,
'LaunchTime': instance['LaunchTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00"),
'InstanceType': instance.get('InstanceType'),
'InstanceState': instance.get('State', {}).get('Name'),
'StateTransitionReason': instance.get('StateTransitionReason')
}
for index, device_mappings in enumerate(instance['BlockDeviceMappings']):
instance['BlockDeviceMappings'][index]['Ebs']['AttachTime'] = device_mappings['Ebs']['AttachTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
for index, network_interface in enumerate(instance['NetworkInterfaces']):
instance['NetworkInterfaces'][index]['Attachment']['AttachTime'] = network_interface['Attachment']['AttachTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
if instance.get('UsageOperationUpdateTime'):
instance['UsageOperationUpdateTime'] = instance['UsageOperationUpdateTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
if instance.get('metrics'):
for index, metric in enumerate(instance['metrics']):
instance['metrics'][index]['Timestamps'] = [date.strftime("%Y-%m-%dT%H:%M:%S+00:00") for date in metric['Timestamps']]
organize_data.append(instance)
instance_data.setdefault('DeviceMappings', [])\
.append(device_mappings['Ebs']['AttachTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00"))
organize_data.append(instance_data)
else:
for volume in resources:
volume_data = {'ResourceId': volume.get('VolumeId'), 'Size': volume.get('Size'),
'VolumeId': volume.get('VolumeId'),
'VolumeState': volume.get('State'), 'Iops': volume.get('Iops'),
'VolumeType': volume.get('VolumeType'),
'User': self._ec2_operations.get_tag_value_from_tags(tags=volume.get('Tags', []), tag_name='User'),
'Policy': self._ec2_operations.get_tag_value_from_tags(tags=volume.get('Tags', []), tag_name='Policy')}
if volume.get('Attachments'):
for attachment in volume.get('Attachments'):
attachment['AttachTime'] = attachment['AttachTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
volume['CreateTime'] = volume['CreateTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
if 'Tags' in volume:
del volume['Tags']
organize_data.append(volume)
volume_data.update({
'AttachTime': attachment['AttachTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")
})
volume_data.update({'CreateTime': volume['CreateTime'].strftime("%Y-%m-%dT%H:%M:%S+00:00")})
organize_data.append(volume_data)
return organize_data

def get_ebs_cost(self, resource: any, resource_type: str, resource_hours: int):
Expand Down
Loading