Skip to content

Commit

Permalink
Update SavingsPlan line items (#527)
Browse files Browse the repository at this point in the history
* Update SavingsplanNegation items
  • Loading branch information
esebesto authored Aug 19, 2024
1 parent 1974bb0 commit 02b12f0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 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.8"
__version__ = "4.6.9"


VERSION = __version__.split(".")
14 changes: 10 additions & 4 deletions nise/generators/aws/data_transfer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def _update_data(self, row, start, end, **kwargs):
row["pricing/term"] = "OnDemand"
row["pricing/unit"] = "GB"
row["savingsPlan/SavingsPlanEffectiveCost"] = str(saving)
row["savingsPlan/SavingsPlanRate"] = str(saving)

# Overwrite lineItem/LineItemType for items with applied Savings plan
if saving is not None:
Expand All @@ -124,11 +125,16 @@ def _update_data(self, row, start, end, **kwargs):
if negation:
row["lineItem/LineItemType"] = "SavingsPlanNegation"
row["lineItem/UnblendedCost"] = -abs(cost)
row["lineItem/LineItemDescription"] = f"SavingsPlanNegation used by AccountId : {self.payer_account}"
row["lineItem/ResourceId"] = None
row["lineItem/UnblendedRate"] = -abs(rate)
row["lineItem/BlendedCost"] = -abs(cost)

if not negation:
row["lineItem/BlendedRate"] = -abs(rate)
row[
"lineItem/LineItemDescription"
] = f"SavingsPlanNegation used by AccountId : {self.payer_account} and UsageSku : {self._product_sku}"
row["lineItem/ResourceId"] = None
row["savingsPlan/SavingsPlanEffectiveCost"] = None
row["savingsPlan/SavingsPlanRate"] = None
else:
self._add_tag_data(row)
self._add_category_data(row)
return row
Expand Down
15 changes: 12 additions & 3 deletions nise/generators/aws/ec2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,29 @@ def _update_data(self, row, start, end, **kwargs):
row["pricing/term"] = "OnDemand"
row["pricing/unit"] = "Hrs"
row["savingsPlan/SavingsPlanEffectiveCost"] = saving
row["savingsPlan/SavingsPlanRate"] = saving

# Overwrite lineItem/LineItemType for items with applied Savings plan
if saving is not None:
row["lineItem/LineItemType"] = "SavingsPlanCoveredUsage"

if negation:
row["lineItem/LineItemType"] = "SavingsPlanNegation"
row["lineItem/UnblendedCost"] = -abs(cost)
row["lineItem/LineItemDescription"] = f"SavingsPlanNegation used by AccountId : {self.payer_account}"
row["lineItem/ResourceId"] = None
row["lineItem/UnblendedRate"] = -abs(rate)
row["lineItem/BlendedCost"] = -abs(cost)
row["lineItem/BlendedRate"] = -abs(rate)
row[
"lineItem/LineItemDescription"
] = f"SavingsPlanNegation used by AccountId : {self.payer_account} and UsageSku : {self._product_sku}"
row["lineItem/ResourceId"] = None
row["savingsPlan/SavingsPlanEffectiveCost"] = None
row["savingsPlan/SavingsPlanRate"] = None

if not negation:
else:
self._add_tag_data(row)
self._add_category_data(row)

return row

def generate_data(self, report_type=None):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aws_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def test_init_with_attributes(self):

def test_update_data_ec2_negation(self):
"""Test EC2 specific update data with negation costs."""
self.instance_type = {"negation": True, "cost": 10}
self.instance_type = {"negation": True, "cost": 10, "rate": 1}
self.attributes["instance_type"] = self.instance_type
generator = EC2Generator(
self.two_hours_ago, self.now, self.currency, self.payer_account, self.usage_accounts, self.attributes
Expand Down

0 comments on commit 02b12f0

Please sign in to comment.