Closed knikolla closed 2 days ago
@knikolla My proposal will be to do the following code changes:
pci_info
below...
https://github.com/CCI-MOC/openstack-billing-from-db/blob/fe0f1f9a61404947f12541d59f5747f6d52804c2/src/openstack_billing_db/model.py#L264-L269...the su_name
string will be renamed as su_type
, and will be defined as follows:
su_type = f"gpu_{pci_name}"
Given that we know pci_name
will be a string within this list...
https://github.com/CCI-MOC/openstack-billing-from-db/blob/fe0f1f9a61404947f12541d59f5747f6d52804c2/src/openstack_billing_db/billing.py#L189-L196
...this will allow us to change this code block... https://github.com/CCI-MOC/openstack-billing-from-db/blob/fe0f1f9a61404947f12541d59f5747f6d52804c2/src/openstack_billing_db/billing.py#L110-L123
...into this:
su_hour_attr = f"{i.service_unit_type}_su_hours"
if hasattr(invoice, su_hour_attr):
invoice.__setattr__(su_hour_attr, invoice.__getattribute__(su_hour_attr) + su_hours)
else:
raise Exception("Invalid flavor.")
Flavor.name
will be renamed to Flavor.type
Flavor.gpu_count
will be added to determine the GPU count, and will default to 0 if not defined. This means service_units()
will be modified like this:
@property
def service_units(self):
if self.gpu_count:
return self.gpu_count
else:
# 1 CPU SU = 0 GPU, 1 CPU, 4 GB RAM, 20 GB
return int(
max(
self.vcpus,
self.memory / 4096,
)
)
The logic for obtaining self.gpu_count will be handled while extracting info from pci_info
@knikolla Do you have any opinion on my proposal?
Sounds okay, start with that and I'll comment more on the code itself.
@knikolla Should I add a test case to make sure the flavor logic is handled correctly?
@knikolla Should I add a test case to make sure the flavor logic is handled correctly?
Yes!
30 removed the dependence on flavor names to figure out the SU type. VMs that had a flavor with
a100
in their name where detected as OpenStack GPUA100. After #30 merged, the way we figure out with SU a VM is, is from the PCI Request field in the instance table.However, we still used that information to reconstruct a flavor name
https://github.com/CCI-MOC/openstack-billing-from-db/blob/7dfbc657d2e93db660b755fa5f6d63475ae57d44/src/openstack_billing_db/model.py#L257-L258
And then further down the execution of the code still use flavor name to find out the flavor type.
https://github.com/CCI-MOC/openstack-billing-from-db/blob/7dfbc657d2e93db660b755fa5f6d63475ae57d44/src/openstack_billing_db/model.py#L21-L54
We should refactor that part of the code to not depend on flavor names anymore.