From 4f427a122fa559c73903c49f9333581b5776e33d Mon Sep 17 00:00:00 2001 From: myersCody Date: Thu, 1 Aug 2024 09:21:45 -0400 Subject: [PATCH] [COST-5430] Adjust EBS rate to be daily --- example_aws_static_data.yml | 15 ++++++++++++++- nise/__init__.py | 2 +- nise/generators/aws/ebs_generator.py | 20 ++++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) mode change 100644 => 100755 example_aws_static_data.yml diff --git a/example_aws_static_data.yml b/example_aws_static_data.yml old mode 100644 new mode 100755 index 2db32a03..d47ad6cf --- a/example_aws_static_data.yml +++ b/example_aws_static_data.yml @@ -1,7 +1,7 @@ --- generators: - EC2Generator: - start_date: 2020-03-01 + start_date: today processor_arch: 32-bit resource_id: 55555555 product_sku: VEAJHRNKTJZQ @@ -52,6 +52,19 @@ family: 'Memory Optimized' cost: 1.000 rate: 0.500 + - EBSGenerator: + start_date: today + product_sku: VEAJHRNBBBBD + resource_id: 12345674 + amount: 8 + rate: 0.1 + tags: + resourceTags/user:storageclass: gamma + resourceTags/user:Mapping: d1 + resourceTags/user:Map: d2 + cost_category: + costCategory/env: ephemeral + accounts: diff --git a/nise/__init__.py b/nise/__init__.py index 0eddf277..384e889b 100644 --- a/nise/__init__.py +++ b/nise/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.6.5" +__version__ = "4.6.6" VERSION = __version__.split(".") diff --git a/nise/generators/aws/ebs_generator.py b/nise/generators/aws/ebs_generator.py index 6460702f..28a6095f 100644 --- a/nise/generators/aws/ebs_generator.py +++ b/nise/generators/aws/ebs_generator.py @@ -15,6 +15,7 @@ # along with this program. If not, see . # """Module for ebs data generation.""" +import calendar from random import choice from random import uniform @@ -53,15 +54,22 @@ def _get_storage(self): """Get storage data.""" return choice(self.STORAGE) + def _calculate_cost_per_day(self, start): + """EBS charges in a monthly rate. + Therefore we need to convert to a daily rate to calculate the cost.""" + num_days_in_month = calendar.monthrange(start.year, start.month)[1] + hours_in_month = num_days_in_month * 24 + daily_rate = self._rate / hours_in_month + return self._amount * daily_rate + def _update_data(self, row, start, end, **kwargs): """Update data with generator specific data.""" row = self._add_common_usage_info(row, start, end) - rate = self._rate amount = self._amount - cost = amount * rate + cost = self._calculate_cost_per_day(start) location, aws_region, _, storage_region = self._get_location() - description = f"${rate} per GB-Month of snapshot data stored - {location}" + description = f"${self._rate} per GB-Month of snapshot data stored - {location}" burst, max_iops, max_thru, max_vol_size, vol_backed, vol_type = self._get_storage() row["lineItem/ProductCode"] = "AmazonEC2" @@ -69,9 +77,9 @@ def _update_data(self, row, start, end, **kwargs): row["lineItem/Operation"] = "CreateVolume" row["lineItem/ResourceId"] = self._resource_id row["lineItem/UsageAmount"] = str(amount) - row["lineItem/UnblendedRate"] = str(rate) + row["lineItem/UnblendedRate"] = str(self._rate) row["lineItem/UnblendedCost"] = str(cost) - row["lineItem/BlendedRate"] = str(rate) + row["lineItem/BlendedRate"] = str(self._rate) row["lineItem/BlendedCost"] = str(cost) row["lineItem/LineItemDescription"] = description row["product/ProductName"] = "Amazon Elastic Compute Cloud" @@ -89,7 +97,7 @@ def _update_data(self, row, start, end, **kwargs): row["product/usagetype"] = f"{storage_region}:VolumeUsage" row["product/volumeType"] = vol_type row["pricing/publicOnDemandCost"] = str(cost) - row["pricing/publicOnDemandRate"] = str(rate) + row["pricing/publicOnDemandRate"] = str(self._rate) row["pricing/term"] = "OnDemand" row["pricing/unit"] = "GB-Mo" self._add_tag_data(row)