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

Implemented 'nerc-rates' for storage invoicing #169

Merged
merged 1 commit into from
Aug 26, 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@74eb4a7#egg=nerc_rates
boto3
coldfront >= 1.0.4
python-cinderclient # TODO: Set version for OpenStack Clients
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package_dir =
packages = find:
python_requires = >=3.8
install_requires =
nerc_rates @ git+https://github.com/CCI-MOC/nerc-rates@74eb4a7
boto3
coldfront >= 1.0.4
python-cinderclient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from coldfront.core.allocation.models import Allocation, AllocationStatusChoice
import pytz

from nerc_rates import load_from_url

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

Expand Down Expand Up @@ -187,6 +189,19 @@ def process_invoice_row(allocation, attrs, su_name, rate):
resources__in=openshift_resources
)

rates = load_from_url()
openstack_storage_rate = openshift_storage_rate = Decimal(
rates.get_value_at('Storage GB Rate', options["invoice_month"]))

if options['openstack_gb_rate']:
openstack_storage_rate = options['openstack_gb_rate']

if options['openshift_gb_rate']:
openshift_storage_rate = options['openshift_gb_rate']

logger.info(f'Using storage rate {openstack_storage_rate} (Openstack) and
{openshift_storage_rate} (Openshift) for {options["invoice_month"]}')

logger.info(f'Writing to {options["output"]}.')
with open(options['output'], 'w', newline='') as f:
csv_invoice_writer = csv.writer(
Expand All @@ -204,7 +219,7 @@ def process_invoice_row(allocation, attrs, su_name, rate):
allocation,
[attributes.QUOTA_VOLUMES_GB, attributes.QUOTA_OBJECT_GB],
"OpenStack Storage",
options['openstack_gb_rate'])
openstack_storage_rate)

for allocation in openshift_allocations:
allocation_str = f'{allocation.pk} of project "{allocation.project.title}"'
Expand All @@ -215,7 +230,7 @@ def process_invoice_row(allocation, attrs, su_name, rate):
allocation,
[attributes.QUOTA_LIMITS_EPHEMERAL_STORAGE_GB, attributes.QUOTA_REQUESTS_STORAGE],
"OpenShift Storage",
options['openshift_gb_rate']
openshift_storage_rate
)

if options['upload_to_s3']:
Expand Down
Loading