Skip to content

Commit 264072a

Browse files
committed
Adding disk_size.
1 parent b88134a commit 264072a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

nise/generators/gcp/compute_engine_generator.py

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class ComputeEngineGenerator(GCPGenerator):
5858

5959
LABELS = (([{"key": "vm_key_proj2", "value": "vm_label_proj2"}]), ([]))
6060

61+
EFFECTIVE_PRICE = ("0.0114", "0.0417", "0.1922", "0.0452")
62+
6163
def __init__(self, start_date, end_date, currency, project, attributes=None): # noqa: C901
6264
"""Initialize the cloud storage generator."""
6365
super().__init__(start_date, end_date, currency, project, attributes)
@@ -123,6 +125,9 @@ def _update_data(self, row): # noqa: C901
123125
row["currency"] = self._currency
124126
row["labels"] = self.determine_labels(self.LABELS)
125127
row["system_labels"] = self.determine_system_labels(sku[3])
128+
row["price.effective_price"] = choice(self.EFFECTIVE_PRICE)
129+
row["disk_size"] = self._generate_disk_size(row["cost"], row["price.effective_price"])
130+
126131
if self.resource_level:
127132
resource = self._generate_resource(
128133
self._resource_name, self._resource_global_name, self.project.get("region")
@@ -183,6 +188,10 @@ def _update_data(self, row): # noqa: C901
183188
month = datetime.strptime(row.get("usage_start_time")[:7], "%Y-%m").month
184189
invoice["month"] = f"{year}{month:02d}"
185190
row["invoice"] = invoice
191+
effective_price = choice(self.EFFECTIVE_PRICE)
192+
row["price"] = {"effective_price": effective_price}
193+
row["disk_size"] = self._generate_disk_size(row["cost"], row["price"]["effective_price"])
194+
186195
if self.resource_level:
187196
resource = self._generate_resource()
188197
row["resource"] = resource

nise/generators/gcp/gcp_generator.py

+12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"cost_type",
5858
"partition_date",
5959
"price.effective_price",
60+
"disk_size",
6061
)
6162

6263
GCP_RESOURCE_COLUMNS = ("resource.name", "resource.global_name")
@@ -320,3 +321,14 @@ def _generate_hourly_data(self, **kwargs):
320321
row = self._init_data_row(start, end)
321322
row = self._update_data(row)
322323
yield row
324+
325+
def _generate_disk_size(self, cost, effective_price):
326+
"""Generate disk size."""
327+
hours_in_month = 744
328+
disk_size = 0
329+
330+
if cost and effective_price:
331+
rate = float(effective_price) / hours_in_month
332+
disk_size = float(cost) / rate
333+
334+
return disk_size

nise/upload.py

+7
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ def gcp_bucket_to_dataset(gcp_bucket_name, file_name, dataset_name, table_name,
269269
"mode": "NULLABLE",
270270
},
271271
{"name": "cost_type", "type": "STRING", "mode": "NULLABLE"},
272+
{
273+
"name": "price",
274+
"type": "RECORD",
275+
"fields": [{"name": "effective_price", "type": "STRING", "mode": "NULLABLE"}],
276+
"mode": "NULLABLE",
277+
},
278+
{"name": "disk_size", "type": "STRING", "mode": "NULLABLE"},
272279
{
273280
"name": "adjustment_info",
274281
"type": "RECORD",

0 commit comments

Comments
 (0)