Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ google-drive-key.json
overrides.yml
New Project Request MOUs
Secure Directory Request MOUs
Service Units Purchase Request MOUs
Service Units Purchase Request MOUs
4 changes: 2 additions & 2 deletions bootstrap/development/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ Note that these steps must be run from the root directory of the repo.
6. Start the application stack. Specify a unique Docker [project name](https://docs.docker.com/compose/project-name/) so that resources are placed within a Docker namespace. Examples: "brc-dev", "lrc-dev".

```bash
export DOCKER_PROJECT_NAME=brc-dev
` export DOCKER_PROJECT_NAME=brc-dev
docker-compose \
-f bootstrap/development/docker/docker-compose.yml \
-p $DOCKER_PROJECT_NAME \
up
up`
```

Notes:
Expand Down
9 changes: 6 additions & 3 deletions coldfront/core/allocation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,16 @@ class AllocationPeriodChoiceField(forms.ModelChoiceField):

def __init__(self, *args, **kwargs):
self.computing_allowance = kwargs.pop('computing_allowance', None)
if (self.computing_allowance is not None and
not isinstance(self.computing_allowance, ComputingAllowance)):
self.computing_allowance = ComputingAllowance(
self.computing_allowance)
self.interface = ComputingAllowanceInterface()
super().__init__(*args, **kwargs)

def label_from_instance(self, obj):
computing_allowance = ComputingAllowance(self.computing_allowance)
num_service_units = self.allocation_value(obj)
if computing_allowance.are_service_units_prorated():
if self.computing_allowance.are_service_units_prorated():
num_service_units = prorated_allocation_amount(
num_service_units, utc_now_offset_aware(), obj)
return (
Expand All @@ -297,7 +300,7 @@ def label_from_instance(self, obj):
def allocation_value(self, obj):
"""Return the allocation value (Decimal) to use based on the
allocation type and the AllocationPeriod."""
allowance_name = self.computing_allowance.name
allowance_name = self.computing_allowance.get_name()
if flag_enabled('BRC_ONLY'):
assert allowance_name in self._allowances_with_periods_brc()
return Decimal(
Expand Down
24 changes: 24 additions & 0 deletions coldfront/core/allocation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ def prorated_allocation_amount(amount, dt, allocation_period):
return Decimal(f'{math.floor(amount):.2f}')


def calculate_service_units_to_allocate(computing_allowance,
request_time, allocation_period=None):
"""Return the number of service units to allocate to a new project
request or allowance renewal request with the given
ComputingAllowance, if it were to be made at the given datetime. If
the request is associated with an AllocationPeriod, use it to
determine the number. Prorate as needed."""
kwargs = {}
if allocation_period is not None:
kwargs['is_timed'] = True
kwargs['allocation_period'] = allocation_period

computing_allowance_interface = ComputingAllowanceInterface()
num_service_units = Decimal(
computing_allowance_interface.service_units_from_name(
computing_allowance.get_name(), **kwargs))

if computing_allowance.are_service_units_prorated():
num_service_units = prorated_allocation_amount(
num_service_units, request_time, allocation_period)

return num_service_units


def review_cluster_access_requests_url():
domain = settings.CENTER_BASE_URL
view = reverse('allocation-cluster-account-request-list')
Expand Down
33 changes: 18 additions & 15 deletions coldfront/core/project/forms_/new_project_forms/request_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ class SavioProjectAllocationPeriodForm(forms.Form):
def __init__(self, *args, **kwargs):
computing_allowance = kwargs.pop('computing_allowance', None)
super().__init__(*args, **kwargs)
display_timezone = pytz.timezone(settings.DISPLAY_TIME_ZONE)
queryset = self.allocation_period_choices(
computing_allowance, utc_now_offset_aware(), display_timezone)
if computing_allowance is not None:
computing_allowance = ComputingAllowance(computing_allowance)
display_timezone = pytz.timezone(settings.DISPLAY_TIME_ZONE)
queryset = self.allocation_period_choices(
computing_allowance, utc_now_offset_aware(), display_timezone)
else:
queryset = AllocationPeriod.objects.none()
self.fields['allocation_period'] = AllocationPeriodChoiceField(
computing_allowance=computing_allowance,
label='Allocation Period',
Expand Down Expand Up @@ -87,32 +91,29 @@ def allocation_period_choices(self, computing_allowance, utc_dt,

def _allocation_period_choices_brc(self, computing_allowance, date, f,
order_by):
"""TODO"""
allowance_name = computing_allowance.name
allowance_name = computing_allowance.get_name()
if allowance_name in (BRCAllowances.FCA, BRCAllowances.PCA):
return self._allocation_period_choices_allowance_year(
date, f, order_by)
computing_allowance, date, f, order_by)
elif allowance_name == BRCAllowances.ICA:
num_days = self.NUM_DAYS_BEFORE_ICA
f = f & Q(start_date__lte=date + timedelta(days=num_days))
f = f & (
Q(name__startswith='Fall Semester') |
Q(name__startswith='Spring Semester') |
Q(name__startswith='Summer Sessions'))
allowance_periods_q = computing_allowance.get_period_filters()
if allowance_periods_q is not None:
f = f & allowance_periods_q
return AllocationPeriod.objects.filter(f).order_by(*order_by)
return AllocationPeriod.objects.none()

def _allocation_period_choices_lrc(self, computing_allowance, date, f,
order_by):
"""TODO"""
allowance_name = computing_allowance.name
if allowance_name == LRCAllowances.PCA:
return self._allocation_period_choices_allowance_year(
date, f, order_by)
computing_allowance, date, f, order_by)
return AllocationPeriod.objects.none()

def _allocation_period_choices_allowance_year(self, date, f, order_by):
"""TODO"""
def _allocation_period_choices_allowance_year(self, computing_allowance,
date, f, order_by):
if flag_enabled('ALLOCATION_RENEWAL_FOR_NEXT_PERIOD_REQUESTABLE'):
# If projects for the next period may be requested, include it.
started_before_date = (
Expand All @@ -126,7 +127,9 @@ def _allocation_period_choices_allowance_year(self, date, f, order_by):
# Otherwise, include only the current period.
started_before_date = date
f = f & Q(start_date__lte=started_before_date)
f = f & Q(name__startswith='Allowance Year')
allowance_periods_q = computing_allowance.get_period_filters()
if allowance_periods_q is not None:
f = f & allowance_periods_q
return AllocationPeriod.objects.filter(f).order_by(*order_by)


Expand Down
Loading