From ad8b24349367339b5e9dbcc7fad8652a64f85407 Mon Sep 17 00:00:00 2001 From: Cody Myers Date: Mon, 20 May 2024 15:31:31 -0400 Subject: [PATCH] [COST-4869] Create Azure managed disk generator (#504) --- example_azure_static_data.yml | 7 +++ nise/__init__.py | 2 +- nise/generators/azure/__init__.py | 1 + nise/generators/azure/azure_generator.py | 18 ++++++- .../azure/managed_disk_generator.py | 47 +++++++++++++++++++ nise/generators/azure/storage_generator.py | 2 - nise/report.py | 2 + 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 nise/generators/azure/managed_disk_generator.py diff --git a/example_azure_static_data.yml b/example_azure_static_data.yml index 0ae1e48b5..11fb0a56b 100644 --- a/example_azure_static_data.yml +++ b/example_azure_static_data.yml @@ -23,6 +23,13 @@ generators: resource_location: "US West" tags: {"environment": "prod", "project":"p3"} additional_info: {"ConsumptionMeter": "1111aaaa-22bb-33cc-44dd-555555eeeeee"} + - ManagedDiskGenerator: + start_date: last_month + meter_id: 55555555-4444-3333-2222-111111111116 + resource_location: "US North Central" + tags: {"environment": "prod", "project":"p3"} + meter_name: "P4 LRS Disk" + resource_name: "azure-cloud-prefix-pvc-volume_2" # SubscriptionGuid diff --git a/nise/__init__.py b/nise/__init__.py index 8188adf08..023beaa04 100644 --- a/nise/__init__.py +++ b/nise/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.5.0" +__version__ = "4.5.1" VERSION = __version__.split(".") diff --git a/nise/generators/azure/__init__.py b/nise/generators/azure/__init__.py index 8ecfce261..8ca6cbf04 100644 --- a/nise/generators/azure/__init__.py +++ b/nise/generators/azure/__init__.py @@ -21,6 +21,7 @@ from nise.generators.azure.bandwidth_generator import BandwidthGenerator # noqa: F401 from nise.generators.azure.ccsp_generator import CCSPGenerator # noqa: F401 from nise.generators.azure.data_transfer_generator import DTGenerator # noqa: F401 +from nise.generators.azure.managed_disk_generator import ManagedDiskGenerator # noqa: F401 from nise.generators.azure.sql_database_generator import SQLGenerator # noqa: F401 from nise.generators.azure.storage_generator import StorageGenerator # noqa: F401 from nise.generators.azure.virtual_machine_generator import VMGenerator # noqa: F401 diff --git a/nise/generators/azure/azure_generator.py b/nise/generators/azure/azure_generator.py index 327ba5eb2..faa0b915b 100644 --- a/nise/generators/azure/azure_generator.py +++ b/nise/generators/azure/azure_generator.py @@ -18,6 +18,7 @@ import calendar import datetime import json +import uuid from random import choice from random import randint from random import uniform @@ -165,6 +166,19 @@ class AzureGenerator(AbstractGenerator): INVOICE_SECTION_NAMES = ("IT Services",) + @property + def meter_id(self): + if self._meter_id is None: + self._meter_id = uuid.uuid4() + return self._meter_id + + @property + def meter_name(self): + if self._meter_name is None: + _, _, meter_name, _ = self._get_cached_meter_values(self.meter_id, self.SERVICE_METER) + self._meter_name = meter_name + return self._meter_name + def __init__(self, start_date, end_date, currency, account_info, attributes=None): # noqa: C901 """Initialize the generator.""" self.azure_columns = AZURE_COLUMNS @@ -355,8 +369,8 @@ def _update_data(self, row, start, end, **kwargs): row["ResourceGroup"] = resource_group row["ResourceLocation"] = azure_region row["MeterCategory"] = self._service_name - row["MeterId"] = str(meter_id) - row["MeterName"] = meter_name + row["MeterId"] = str(self.meter_id) + row["MeterName"] = self.meter_name row["MeterRegion"] = meter_region row["ConsumedService"] = self._consumed row["OfferId"] = "" diff --git a/nise/generators/azure/managed_disk_generator.py b/nise/generators/azure/managed_disk_generator.py new file mode 100644 index 000000000..498389b4c --- /dev/null +++ b/nise/generators/azure/managed_disk_generator.py @@ -0,0 +1,47 @@ +# +# Copyright 2024 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +"""Module for azure bandwidth data generation.""" +from nise.generators.azure.azure_generator import AzureGenerator + + +class ManagedDiskGenerator(AzureGenerator): + """Generator for Storage data.""" + + # service_tier, meter_subject, meter_name, units_of_measure + SERVICE_METER = ( + ("Standard SSD Managed Disks", "Standard SSD Managed Disks", "E4 Disks", "1 /Month"), + ("Standard SSD Managed Disks", "Standard SSD Managed Disks", "Disk Operations", "100000000"), + ("Premium SSD Managed Disks", "Premium SSD Managed Disks", "P10 Disks", ""), + ("Premium SSD Managed Disks", "Premium SSD Managed Disks", "Disk Operations", ""), + ) + SERVICE_INFO_2 = [None] + EXAMPLE_RESOURCE = ( + ("RG1", "mysa1"), + ("RG1", "costmgmtacct1234"), + ("RG2", "mysa1"), + ("RG2", "costmgmtacct1234"), + ("costmgmt", "mysa1"), + ("costmgmt", "costmgmtacct1234"), + ("hccm", "mysa1"), + ("hccm", "costmgmtacct1234"), + ) + ADDITIONAL_INFO = [None] + + def __init__(self, start_date, end_date, currency, account_info, attributes=None): + """Initialize the data transfer generator.""" + self._service_name = "Storage" + super().__init__(start_date, end_date, currency, account_info, attributes) diff --git a/nise/generators/azure/storage_generator.py b/nise/generators/azure/storage_generator.py index 8ff2310cc..49802324f 100644 --- a/nise/generators/azure/storage_generator.py +++ b/nise/generators/azure/storage_generator.py @@ -41,9 +41,7 @@ class StorageGenerator(AzureGenerator): ("Tables", "Tables", "Read Operations", "1000000"), ("Tables", "Tables", "LRS Data Stored", "100 GB/Month"), ("Tables", "Tables", "RA-GRS Data Stored", "100 GB/Month"), - ("Standard SSD Managed Disks", "Standard SSD Managed Disks", "E4 Disks", "1 /Month"), ("Standard SSD Managed Disks", "Standard SSD Managed Disks", "Disk Operations", "100000000"), - ("Premium SSD Managed Disks", "Premium SSD Managed Disks", "P10 Disks", ""), ("Premium SSD Managed Disks", "Premium SSD Managed Disks", "Disk Operations", ""), ("Standard Page Blob", "Standard Page Blob", "Disk Read Operations", "100000000"), ("Standard Page Blob", "Standard Page Blob", "Disk Write Operations", "100000000"), diff --git a/nise/report.py b/nise/report.py index fa6ddfe21..7c9c58bb7 100644 --- a/nise/report.py +++ b/nise/report.py @@ -54,6 +54,7 @@ from nise.generators.azure import BandwidthGenerator from nise.generators.azure import CCSPGenerator from nise.generators.azure import DTGenerator +from nise.generators.azure import ManagedDiskGenerator from nise.generators.azure import SQLGenerator from nise.generators.azure import StorageGenerator from nise.generators.azure import VMGenerator @@ -751,6 +752,7 @@ def azure_create_report(options): # noqa: C901 {"generator": VMGenerator, "attributes": {}}, {"generator": VNGenerator, "attributes": {}}, {"generator": DTGenerator, "attributes": {}}, + {"generator": ManagedDiskGenerator, "attributes": {}}, ] accounts_list = None