From 92ec26bd8a05a8c1b061e61b8f6baf8a9441144b Mon Sep 17 00:00:00 2001 From: Cody Myers Date: Tue, 13 Aug 2024 09:14:13 -0400 Subject: [PATCH] [COST-5430] Adjust EBS rate to be a daily rate (#523) * [COST-5430] Adjust EBS rate to be daily --- example_aws_static_data.yml | 15 ++++++++++++++- nise/__init__.py | 3 ++- nise/generators/aws/ebs_generator.py | 20 ++++++++++++++------ 3 files changed, 30 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 384e889b..4923981a 100644 --- a/nise/__init__.py +++ b/nise/__init__.py @@ -1,3 +1,4 @@ -__version__ = "4.6.6" +__version__ = "4.6.7" + 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)