Skip to content

Commit

Permalink
dependency updates
Browse files Browse the repository at this point in the history
  • Loading branch information
djnakabaale committed Aug 17, 2023
2 parents 9e9ac47 + ac3edd4 commit 30aac22
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 264 deletions.
506 changes: 253 additions & 253 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions example_aws_static_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
resourceTags/user:version: alpha
instance_type:
inst_type: m5.large
physical_cores: 1
vcpu: 2
memory: '8 GiB'
storage: 'EBS Only'
Expand All @@ -28,6 +29,7 @@
resourceTags/user:version: alpha
instance_type:
inst_type: m5.large
physical_cores: 1
vcpu: 2
memory: '8 GiB'
storage: 'EBS Only'
Expand Down
2 changes: 1 addition & 1 deletion nise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.2.8"
__version__ = "4.3.4"

VERSION = __version__.split(".")
1 change: 1 addition & 0 deletions nise/generators/aws/aws_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"product/operation",
"product/operationsSupport",
"product/origin",
"product/physicalCores",
"product/physicalProcessor",
"product/platousagetype",
"product/platovolumetype",
Expand Down
4 changes: 4 additions & 0 deletions nise/generators/aws/data_transfer_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ def _update_data(self, row, start, end, **kwargs):
row["pricing/term"] = "OnDemand"
row["pricing/unit"] = "GB"
row["savingsPlan/SavingsPlanEffectiveCost"] = str(saving)

# Overwrite lineItem/LineItemType for items with applied Savings plan
if saving is not None:
row["lineItem/LineItemType"] = "SavingsPlanCoveredUsage"
self._add_tag_data(row)
self._add_category_data(row)
return row
Expand Down
15 changes: 14 additions & 1 deletion nise/generators/aws/ec2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class EC2Generator(AWSGenerator):
"""Generator for EC2 data."""

INSTANCE_TYPES = (
# NOTE: Each tuple represents
# (instance type, physical_cores, vCPUs, memory, storage, family, cost, rate, savings, description)
(
"m5.large",
"1",
"2",
"8 GiB",
"EBS Only",
Expand All @@ -37,6 +40,7 @@ class EC2Generator(AWSGenerator):
),
(
"c5d.2xlarge",
"4",
"8",
"16 GiB",
"1 x 200 NVMe SSD",
Expand All @@ -48,6 +52,7 @@ class EC2Generator(AWSGenerator):
),
(
"c4.xlarge",
"2",
"4",
"7.5 GiB",
"EBS-Only",
Expand All @@ -59,6 +64,7 @@ class EC2Generator(AWSGenerator):
),
(
"r4.large",
"1",
"2",
"15.25 GiB",
"EBS-Only",
Expand Down Expand Up @@ -92,6 +98,7 @@ def __init__(self, start_date, end_date, currency, payer_account, usage_accounts
if instance_type:
self._instance_type = (
instance_type.get("inst_type"),
instance_type.get("physical_cores"),
instance_type.get("vcpu"),
instance_type.get("memory"),
instance_type.get("storage"),
Expand All @@ -104,7 +111,7 @@ def __init__(self, start_date, end_date, currency, payer_account, usage_accounts

def _update_data(self, row, start, end, **kwargs):
"""Update data with generator specific data."""
inst_type, vcpu, memory, storage, family, cost, rate, saving, description = self._instance_type
inst_type, physical_cores, vcpu, memory, storage, family, cost, rate, saving, description = self._instance_type
inst_description = description.format(cost, inst_type)
location, aws_region, avail_zone, _ = self._get_location()
row = self._add_common_usage_info(row, start, end)
Expand Down Expand Up @@ -134,6 +141,7 @@ def _update_data(self, row, start, end, **kwargs):
row["product/networkPerformance"] = "Moderate"
row["product/operatingSystem"] = "Linux"
row["product/operation"] = "RunInstances"
row["product/physicalCores"] = physical_cores
row["product/physicalProcessor"] = "Intel Xeon Family"
row["product/preInstalledSw"] = "NA"
row["product/processorArchitecture"] = self._processor_arch
Expand All @@ -151,6 +159,11 @@ def _update_data(self, row, start, end, **kwargs):
row["pricing/term"] = "OnDemand"
row["pricing/unit"] = "Hrs"
row["savingsPlan/SavingsPlanEffectiveCost"] = saving

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

self._add_tag_data(row)
self._add_category_data(row)
return row
Expand Down
8 changes: 5 additions & 3 deletions nise/generators/azure/azure_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
"exchangeRateDate",
)

DATE_FMT = "%Y-%m-%d"


class AzureGenerator(AbstractGenerator):
"""Defines an abstract class for generators."""
Expand Down Expand Up @@ -305,9 +307,9 @@ def _add_common_usage_info(self, row, start, end, **kwargs):
row["BillingAccountName"] = self.account_info.get("billing_account_name")
row["BillingProfileId"] = self.account_info.get("billing_account_id")
row["BillingProfileName"] = self.account_info.get("billing_account_name")
row["Date"] = start.date().strftime("%m/%d/%Y")
row["BillingPeriodStartDate"] = self.first_day_of_month(start).strftime("%m/%d/%Y")
row["BillingPeriodEndDate"] = self.last_day_of_month(start).strftime("%m/%d/%Y")
row["Date"] = start.date().strftime(DATE_FMT)
row["BillingPeriodStartDate"] = self.first_day_of_month(start).strftime(DATE_FMT)
row["BillingPeriodEndDate"] = self.last_day_of_month(start).strftime(DATE_FMT)
else:
row["SubscriptionGuid"] = self.subscription_guid
row["UsageDateTime"] = start
Expand Down
11 changes: 7 additions & 4 deletions nise/generators/ocp/ocp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@
OCP_ROS_USAGE: OCP_ROS_USAGE_COLUMN,
}

# No recommendations are generated for job and manual_pod workloads! Keep these two options as the last two items
# in the dict to guarantee they are not randomly picked in get_owner_workload function.
OCP_OWNER_WORKLOAD_CHOICES = {
# "pod": ("<none>", "<none>", None, None), # manually created Pod - recommendation won't be generated
"deployment": (None, "ReplicaSet", None, "deployment"),
"replicaset": (None, "ReplicaSet", "<none>", "deployment"), # manually created ReplicaSet
"replicationcontroller": (
Expand All @@ -149,15 +150,17 @@
"deploymentconfig": (None, "ReplicationController", None, "deploymentconfig"),
"statefulset": (None, "StatefulSet", None, "statefulset"),
"daemonset": (None, "DaemonSet", None, "daemonset"),
# "job": (None, "Job", None, "job"), # not supported by Kruize
"job": (None, "Job", None, "job"), # not supported by Kruize - recommendation won't be generated!
"manual_pod": ("<none>", "<none>", None, None), # manually created Pod - recommendation won't be generated!
}


def get_owner_workload(pod, workload=None):
if not workload:
workload = choice(list(OCP_OWNER_WORKLOAD_CHOICES.keys()))
workload = choice(list(OCP_OWNER_WORKLOAD_CHOICES.keys())[:-2]) # omit job and manual_pod from random choices
on, ok, wl, wt = OCP_OWNER_WORKLOAD_CHOICES.get(
workload.lower(), choice(list(OCP_OWNER_WORKLOAD_CHOICES.values()))
workload.lower(),
choice(list(OCP_OWNER_WORKLOAD_CHOICES.values())[:-2]), # omit job and manual_pod from random choices
)
if on == "<none>" and wl == "<none>": # manually created Pod
return on, ok, wl, wt
Expand Down
4 changes: 3 additions & 1 deletion nise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,15 @@ def _generate_azure_account_info(static_report_data=None):
company_name = fake.company()
company_email = company_name.replace(" ", "").replace(",", "")
email_suffix = f"@{company_email}.com"
subscription_name = f"{company_name} Azure Subscription"

billing_account_id = fake.ean(length=8)
billing_account_name = company_name
accounts = []
if static_report_data:
subscription_guid = static_report_data.get("payer")
usage_accounts = tuple(static_report_data.get("user"))
currency_code = static_report_data.get("currency_code", "USD")
subscription_name = static_report_data.get("subscription_name", f"{company_name} Azure Subscription")
for _ in usage_accounts:
account_name = fake.city()
trimmed_account_name = account_name.replace(" ", "")
Expand All @@ -379,6 +380,7 @@ def _generate_azure_account_info(static_report_data=None):
fake.ean(length=13),
)
currency_code = "USD"
subscription_name = f"{company_name} Azure Subscription"
for _ in usage_accounts:
account_name = fake.city()
trimmed_account_name = account_name.replace(" ", "")
Expand Down
1 change: 1 addition & 0 deletions nise/yaml_generators/static/aws_static_data.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ generators:
processor_arch: {{ ec2.processor_arch }}
instance_type:
inst_type: {{ ec2.instance_type.inst_type }}
physical_cores: {{ ec2.instance_type.physical_cores }}
vcpu: {{ ec2.instance_type.vcpu }}
memory: {{ ec2.instance_type.memory }}
storage: {{ ec2.instance_type.storage }}
Expand Down
1 change: 1 addition & 0 deletions tests/aws_static_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ generators:
resourceTags/user:version: alpha
instance_type:
inst_type: m5.large
physical_cores: 1
vcpu: 2
memory: '8 GiB'
storage: 'EBS Only'
Expand Down
1 change: 1 addition & 0 deletions tests/test_aws_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def test_init_with_attributes(self):
"""Test the unique init options for Data Transfer."""
self.instance_type = {
"inst_type": "1",
"physical_cores": "1",
"vcpu": "1",
"memory": "1",
"storage": "1",
Expand Down
8 changes: 7 additions & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,12 @@ def test_azure_create_report_with_static_data(self, mock_name):
"end_date": str(now.date() + relativedelta(months=+2)),
}
},
]
],
"accounts": {
"payer": "38f1d748-3ac7-4b7f-a5ae-8b5ff16db82c",
"user": ["38f1d748-3ac7-4b7f-a5ae-8b5ff16db82c"],
"subscription_name": "static_subscription_name",
},
}
options = {
"start_date": yesterday,
Expand All @@ -1205,6 +1210,7 @@ def test_azure_create_report_with_static_data(self, mock_name):
"static_report_data": static_azure_data,
"write_monthly": True,
}

azure_create_report(options)
local_path = self.MOCK_AZURE_REPORT_FILENAME
self.assertTrue(os.path.isfile(local_path))
Expand Down

0 comments on commit 30aac22

Please sign in to comment.