diff --git a/coldfront/core/allocation/management/commands/add_allocation_defaults.py b/coldfront/core/allocation/management/commands/add_allocation_defaults.py
index 116111ec6..92598c24f 100644
--- a/coldfront/core/allocation/management/commands/add_allocation_defaults.py
+++ b/coldfront/core/allocation/management/commands/add_allocation_defaults.py
@@ -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),
diff --git a/coldfront/core/allocation/models.py b/coldfront/core/allocation/models.py
index cf1d4cecb..2bba7c5bd 100644
--- a/coldfront/core/allocation/models.py
+++ b/coldfront/core/allocation/models.py
@@ -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')
diff --git a/coldfront/core/allocation/templates/allocation/allocation_detail.html b/coldfront/core/allocation/templates/allocation/allocation_detail.html
index a1709100a..e124975c2 100644
--- a/coldfront/core/allocation/templates/allocation/allocation_detail.html
+++ b/coldfront/core/allocation/templates/allocation/allocation_detail.html
@@ -143,6 +143,14 @@
Allocation Information
Last Synced {{user_sync_dt}}
+
+ {% if "Compute" in allocation.get_parent_resource.resource_type.name %}
+
+ Fairshare: |
+ {{ allocation.fairshare }} |
+
+ {% endif %}
+
{% if "Storage" in allocation.get_parent_resource.resource_type.name %}
Quota (TB): |
diff --git a/coldfront/plugins/slurm/associations.py b/coldfront/plugins/slurm/associations.py
index 9d25674c0..e8de440cc 100644
--- a/coldfront/plugins/slurm/associations.py
+++ b/coldfront/plugins/slurm/associations.py
@@ -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:
@@ -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):
diff --git a/coldfront/plugins/slurm/management/commands/slurm_sync.py b/coldfront/plugins/slurm/management/commands/slurm_sync.py
index d8569872c..6de8c91fb 100644
--- a/coldfront/plugins/slurm/management/commands/slurm_sync.py
+++ b/coldfront/plugins/slurm/management/commands/slurm_sync.py
@@ -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,
)
@@ -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():
@@ -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)
+ )