Skip to content

Commit

Permalink
Merge pull request #50 from knikolla/sxm4
Browse files Browse the repository at this point in the history
Split out SXM4s
  • Loading branch information
knikolla authored Apr 3, 2024
2 parents 9876eef + cea3f17 commit a642229
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/run_invoicing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python -m openstack_billing_db.main \
--download-sql-dump-from-s3 True \
--convert-sql-dump-file-to-sqlite True \
--rate-cpu-su 0.013 \
--rate-gpu-a100sxm4-su 2.078 \
--rate-gpu-a100-su 1.803 \
--rate-gpu-v100-su 1.214 \
--rate-gpu-k80-su 0.463 \
Expand Down
9 changes: 8 additions & 1 deletion src/openstack_billing_db/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Rates(object):
cpu: Decimal
gpu_a100: Decimal
gpu_a100sxm4: Decimal
gpu_v100: Decimal
gpu_a2: Decimal
gpu_k80: Decimal
Expand All @@ -23,6 +24,7 @@ class Rates(object):

cpu_su_name: str = "OpenStack CPU"
gpu_a100_su_name: str = "OpenStack GPUA100"
gpu_a100sxm4_su_name: str = "OpenStack GPUA100SXM4"
gpu_v100_su_name: str = "OpenStack GPUV100"
gpu_a2_su_name: str = "OpenStack GPUA2"
gpu_k80_su_name: str = "OpenStack GPUK80"
Expand All @@ -43,6 +45,7 @@ class ProjectInvoice(object):
rates: Rates

cpu_su_hours: int = 0
gpu_a100sxm4_su_hours: int = 0
gpu_a100_su_hours: int = 0
gpu_v100_su_hours: int = 0
gpu_k80_su_hours: int = 0
Expand Down Expand Up @@ -99,6 +102,8 @@ def collect_invoice_data_from_openstack(database, billing_start, billing_end, ra

if i.service_unit_type == "CPU":
invoice.cpu_su_hours += su_hours
elif i.service_unit_type == "GPU A100SXM4":
invoice.gpu_a100sxm4_su_hours += su_hours
elif i.service_unit_type == "GPU A100":
invoice.gpu_a100_su_hours += su_hours
elif i.service_unit_type == "GPU V100":
Expand Down Expand Up @@ -173,7 +178,9 @@ def write(invoices, output, invoice_month=None):
)

for invoice in invoices:
for invoice_type in ['cpu', 'gpu_a100', 'gpu_v100', 'gpu_k80', 'gpu_a2']:
for invoice_type in [
'cpu', 'gpu_a100sxm4', 'gpu_a100', 'gpu_v100', 'gpu_k80', 'gpu_a2'
]:
# Each project gets two rows, one for CPU and one for GPU
hours = invoice.__getattribute__(f"{invoice_type}_su_hours")
rate = invoice.rates.__getattribute__(invoice_type)
Expand Down
7 changes: 7 additions & 0 deletions src/openstack_billing_db/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def main():
type=Decimal,
help="Rate of CPU SU/hr"
)
parser.add_argument(
"--rate-gpu-a100sxm4-su",
default=0,
type=Decimal,
help="Rate of GPU A100SXM4 SU/hr"
)
parser.add_argument(
"--rate-gpu-a100-su",
default=0,
Expand Down Expand Up @@ -175,6 +181,7 @@ def main():

rates = billing.Rates(
cpu=args.rate_cpu_su,
gpu_a100sxm4=args.rate_gpu_a100sxm4_su,
gpu_a100=args.rate_gpu_a100_su,
gpu_v100=args.rate_gpu_v100_su,
gpu_k80=args.rate_gpu_k80_su,
Expand Down
4 changes: 3 additions & 1 deletion src/openstack_billing_db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def service_units(self):
def service_unit_type(self):
if "gpu" not in self.name:
return "CPU"
elif "a100" in self.name:
elif "a100-sxm4" in self.name:
return "GPU A100SXM4"
elif "a100" in self.name and "sxm4" not in self.name:
return "GPU A100"
elif "v100" in self.name:
return "GPU V100"
Expand Down

0 comments on commit a642229

Please sign in to comment.