Skip to content

Commit

Permalink
[COST-4869] Create Azure managed disk generator (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
myersCody authored May 20, 2024
1 parent 062f493 commit ad8b243
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
7 changes: 7 additions & 0 deletions example_azure_static_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.5.0"
__version__ = "4.5.1"

VERSION = __version__.split(".")
1 change: 1 addition & 0 deletions nise/generators/azure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions nise/generators/azure/azure_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import calendar
import datetime
import json
import uuid
from random import choice
from random import randint
from random import uniform
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"] = ""
Expand Down
47 changes: 47 additions & 0 deletions nise/generators/azure/managed_disk_generator.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#
"""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)
2 changes: 0 additions & 2 deletions nise/generators/azure/storage_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions nise/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ad8b243

Please sign in to comment.