Skip to content

Commit

Permalink
add fairshare to allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Nov 14, 2023
1 parent 4ab0641 commit f6f5978
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def handle(self, *args, **options):
('High Security', 'Yes/No', False, False),
('DUA', 'Yes/No', False, False),
('External Sharing', 'Yes/No', False, False),
('Fairshare', 'Int', False, False),
# UBCCR defaults
('Cloud Account Name', 'Text', False, False),
# ('CLOUD_USAGE_NOTIFICATION', 'Yes/No', False, True),
Expand Down
4 changes: 4 additions & 0 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def save(self, *args, **kwargs):
def offer_letter_code(self):
return self.get_attribute('Offer Letter Code')

@property
def fairshare(self):
return self.get_attribute('Fairshare')

@property
def expense_code(self):
return self.get_attribute('Expense Code')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ <h3><i class="fas fa-list" aria-hidden="true"></i> Allocation Information</h3>
<span class="float-right">Last Synced {{user_sync_dt}}</span>
</td>
</tr>

{% if "Compute" in allocation.get_parent_resource.resource_type.name %}
<tr>
<th scope="row" class="text-nowrap">Fairshare:</th>
<td id = "group_quota">{{ allocation.fairshare }}</td>
</tr>
{% endif %}

{% if "Storage" in allocation.get_parent_resource.resource_type.name %}
<tr>
<th scope="row" class="text-nowrap">Quota (TB):</th>
Expand Down
17 changes: 11 additions & 6 deletions coldfront/plugins/slurm/associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ def spec_list(self):

return list(set(items))

def format_specs(self):
"""Format unique list of Slurm Specs"""
items = []
def spec_dict(self):
"""Return dict of Slurm Specs"""
spec_dict = {}
for s in self.specs:
for i in s.split(':'):
items.append(i)
for k, v in s.split(':'):
spec_dict[k] = v
return spec_dict

return ':'.join([x for x in self.spec_list()])
def format_specs(self):
"""Format unique list of Slurm Specs"""
return ':'.join(self.spec_list())

def _write(self, out, data):
try:
Expand Down Expand Up @@ -232,6 +235,8 @@ def write_users(self, out):


class SlurmUser(SlurmBase):
"""Create a new SlurmUser by parsing a line from sacctmgr dump. For
example: User - 'jdoe':DefaultAccount='doe_lab':Fairshare=100:MaxSubmitJobs=101"""

@staticmethod
def new_from_sacctmgr(line):
Expand Down
28 changes: 17 additions & 11 deletions coldfront/plugins/slurm/management/commands/slurm_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from django.core.management.base import BaseCommand
from django.utils import timezone
from django.contrib.auth import get_user_model

from coldfront.core.project.models import Project
from coldfront.core.allocation.models import (
Allocation,
AllocationAttribute,
AllocationStatusChoice,
AllocationAttributeType,
)
Expand Down Expand Up @@ -55,7 +54,9 @@ def handle(self, *args, **options):
cloud_acct_name_attr_type_obj = AllocationAttributeType.objects.get(
name='Cloud Account Name')
hours_attr_type_obj = AllocationAttributeType.objects.get(
name='Core Usage (Hours)')
name='Core Usage (Hours)')
fairshare_attr_type_obj = AllocationAttributeType.objects.get(
name='Fairshare')

for resource, cluster in slurm_clusters.items():

Expand Down Expand Up @@ -93,12 +94,17 @@ def handle(self, *args, **options):
allocation_attribute_type=hours_attr_type_obj,
defaults= {'value': 0})

# for username, user in account.users.items():
# print(username, user.specs)
account_spec_dict = account.spec_dict()

# cluster=resource;
# account=allocation;
# organization=project;
# parent=project;
# user=allocationuser
# All the data we need: allocation, project, users, usages
fairshare = account_spec_dict['Fairshare']

if fairshare:
allocation_obj.allocationattribute_set.get_or_create(
allocation_attribute_type=fairshare_attr_type_obj,
defaults= {'value': fairshare})

# add allocationusers from account
for user_name, user_account in account.users:
alloc_user, _ = allocation_obj.allocationuser_set.get_or_create(
user = get_user_model().objects.get(username=user_name)
)

0 comments on commit f6f5978

Please sign in to comment.