Skip to content

Commit

Permalink
EBS: Add disk_size param to calculate hourly usage & rate
Browse files Browse the repository at this point in the history
  • Loading branch information
myersCody committed Aug 15, 2024
1 parent 92ec26b commit 46e36a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.6.7"
__version__ = "4.6.8"


VERSION = __version__.split(".")
20 changes: 9 additions & 11 deletions nise/generators/aws/ebs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,38 @@ def __init__(self, start_date, end_date, currency, payer_account, usage_accounts
"""Initialize the EBS generator."""
super().__init__(start_date, end_date, currency, payer_account, usage_accounts, attributes, tag_cols)
self._resource_id = "vol-{}".format(self.fake.ean8())
self._amount = uniform(0.2, 300.99)
self._disk_size = choice([5, 10, 15, 20, 25])
self._rate = round(uniform(0.02, 0.16), 3)
self._product_sku = self.fake.pystr(min_chars=12, max_chars=12).upper()

if self.attributes:
if self.attributes.get("resource_id"):
self._resource_id = "vol-{}".format(self.attributes.get("resource_id"))
if self.attributes.get("amount"):
self._amount = float(self.attributes.get("amount"))
if self.attributes.get("rate"):
self._rate = float(self.attributes.get("rate"))
if self.attributes.get("product_sku"):
self._product_sku = self.attributes.get("product_sku")
if self.attributes.get("tags"):
self._tags = self.attributes.get("tags")
if _disk_size := self.attributes.get("disk_size"):
self._disk_size = int(_disk_size)

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."""
def _calculate_hourly_rate(self, start):
"""Calculates the houly rate based of the provided monthly rate."""
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
return self._rate / hours_in_month

def _update_data(self, row, start, end, **kwargs):
"""Update data with generator specific data."""
row = self._add_common_usage_info(row, start, end)

amount = self._amount
cost = self._calculate_cost_per_day(start)
hourly_rate = self._calculate_hourly_rate(start)
cost = round(self._disk_size * hourly_rate, 10)
amount = round(cost / self._rate, 10)
location, aws_region, _, storage_region = self._get_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()
Expand Down

0 comments on commit 46e36a6

Please sign in to comment.