Skip to content

Commit

Permalink
Merge pull request #169 from QuanMPhm/167/use_nerc_rates
Browse files Browse the repository at this point in the history
Implemented 'nerc-rates' for storage invoicing
  • Loading branch information
knikolla authored Aug 26, 2024
2 parents 07afcf0 + 1518986 commit 591aa23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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

0 comments on commit 591aa23

Please sign in to comment.