Skip to content

[COST-5432] - Add the ability to generate reserved instances #538

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

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
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.7.0"
__version__ = "4.7.1"


VERSION = __version__.split(".")
20 changes: 20 additions & 0 deletions nise/generators/aws/ec2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class EC2Generator(AWSGenerator):
"0.045",
1,
False,
False,
"${cost} per On Demand Linux {inst_type} Instance Hour",
),
(
Expand All @@ -52,6 +53,7 @@ class EC2Generator(AWSGenerator):
"0.17",
1,
False,
False,
"${cost} per On Demand Linux {inst_type} Instance Hour",
),
(
Expand All @@ -66,6 +68,7 @@ class EC2Generator(AWSGenerator):
"0.099",
1,
False,
False,
"${cost} per On Demand Linux {inst_type} Instance Hour",
),
(
Expand All @@ -80,6 +83,7 @@ class EC2Generator(AWSGenerator):
"0.067",
1,
False,
False,
"${cost} per On Demand Linux {inst_type} Instance Hour",
),
)
Expand Down Expand Up @@ -124,6 +128,7 @@ def __init__(self, start_date, end_date, currency, payer_account, usage_accounts
instance_type.get("rate"),
instance_type.get("saving"),
instance_type.get("amount", "1"),
instance_type.get("reserved_instance", False),
instance_type.get("negation", False),
"${cost} per On Demand Linux {inst_type} Instance Hour",
)
Expand All @@ -141,6 +146,7 @@ def _update_data(self, row, start, end, **kwargs):
rate,
saving,
amount,
reserved_instance,
negation,
description,
) = self._instance_type
Expand Down Expand Up @@ -203,6 +209,20 @@ def _update_data(self, row, start, end, **kwargs):
# Overwrite lineItem/LineItemType for items with applied Savings plan
if saving is not None:
row["lineItem/LineItemType"] = "SavingsPlanCoveredUsage"
# Overwrite lineitem/LineItemType for RI's discount usage
if reserved_instance:
row["lineItem/LineItemType"] = "DiscountedUsage"
row["lineItem/UnblendedCost"] = 0
row["lineItem/UnblendedRate"] = 0
row["lineItem/BlendedCost"] = 0
row["lineItem/BlendedRate"] = 0
row[
"lineItem/LineItemDescription"
] = f"{inst_type} reserved instance applied"
row["pricing/publicOnDemandCost"] = 'convertible'
row["pricing/publicOnDemandRate"] = 'No Upfront'
row["savingsPlan/SavingsPlanEffectiveCost"] = None
row["savingsPlan/SavingsPlanRate"] = None

if negation:
row["lineItem/LineItemType"] = "SavingsPlanNegation"
Expand Down
8 changes: 8 additions & 0 deletions tests/aws_static_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ generators:
cost: 1.000
rate: 0.500
saving: 0.250
- EC2Generator:
start_date: today
end_date: today
processor_arch: 32-bit
resource_id: 55555555
product_sku: VEAJHRNKTJZQ
region: us-east-1a
resourved_instance: true
- S3Generator:
start_date: last_month
end_date: last_month
Expand Down
13 changes: 13 additions & 0 deletions tests/test_aws_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ def test_init_with_attributes(self):
"rate": "1",
"saving": "1",
"amount": 1,
"reserved_instance": False,
"negation": False,
}
self.attributes["instance_type"] = self.instance_type
Expand All @@ -419,6 +420,18 @@ def test_update_data_ec2_negation(self):

self.assertEqual(row["lineItem/LineItemType"], "SavingsPlanNegation")

def test_update_data_ec2_reserved_instances(self):
"""Test EC2 specific update data with Reserved Instances."""
self.instance_type = {"reserved_instance": True}
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
)
start_row = {}
row = generator._update_data(start_row, self.two_hours_ago, self.now)

self.assertEqual(row["lineItem/LineItemType"], "DiscountedUsage")

def test_update_data(self):
"""Test EBS specific update data method."""
generator = EC2Generator(
Expand Down
Loading