Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemeted nerc-rates repo into Openstack billing #71

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
git+https://github.com/CCI-MOC/nerc-rates#egg=nerc_rates
boto3
dataclasses-json
requests
48 changes: 39 additions & 9 deletions src/openstack_billing_db/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from openstack_billing_db import billing, fetch, utils

from nerc_rates import load_from_url

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -165,6 +167,11 @@ def main():
default="/tmp/openstack_invoices.csv",
help="Output path for invoice in CSV format.",
)
parser.add_argument(
"--use-nerc-rates",
action="store_true",
help="Set to use usage rates from nerc-rates repo instead of cli arguements",
)

args = parser.parse_args()

Expand Down Expand Up @@ -192,15 +199,38 @@ def main():
if coldfront_data_file:
logger.info(f"Using ColdFront data file at {coldfront_data_file}.")

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,
gpu_a2=args.rate_gpu_a2_su,
include_stopped_runtime=args.include_stopped_runtime,
)
if args.use_nerc_rates:
nerc_repo_rates = load_from_url()
rates = billing.Rates(
cpu=nerc_repo_rates.get_value_at("CPU SU Rate", args.invoice_month),
gpu_a100sxm4=nerc_repo_rates.get_value_at(
"GPUA100SXM4 SU Rate", args.invoice_month
),
gpu_a100=nerc_repo_rates.get_value_at(
"GPUA100 SU Rate", args.invoice_month
),
gpu_v100=nerc_repo_rates.get_value_at(
"GPUV100 SU Rate", args.invoice_month
),
gpu_k80=nerc_repo_rates.get_value_at("GPUK80 SU Rate", args.invoice_month),
gpu_a2=nerc_repo_rates.get_value_at("GPUA2 SU Rate", args.invoice_month),
include_stopped_runtime=(
nerc_repo_rates.get_value_at(
"Charge for Stopped Instances", args.invoice_month
)
== "True"
),
)
else:
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,
gpu_a2=args.rate_gpu_a2_su,
include_stopped_runtime=args.include_stopped_runtime,
)

billing.generate_billing(
args.start,
Expand Down
Loading