Skip to content
Closed
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
18 changes: 18 additions & 0 deletions schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,24 @@ def repoComputeAllocationUpsert(self, repo: RepoInput, repocompute: RepoComputeA
clustername = repocompute.clustername
if not info.context.db.find_clusters({"name": clustername}):
raise Exception("Cannot find cluster with name " + clustername)

# Validate facility has purchased resources on this cluster
facility_name = repo.facility
todaysdate = datetime.utcnow()

purchase = info.context.db.collection("facility_compute_purchases").find_one({
"facility": facility_name,
"clustername": clustername,
"start": {"$lte": todaysdate},
"end": {"$gt": todaysdate},
"servers": {"$gt": 0}
})

if not purchase:
raise Exception(
f"Cannot create allocation for cluster '{clustername}': "
f"Facility '{facility_name}' has not purchased compute resources on this cluster. "
)

rc["clustername"] = clustername
rc["start"] = repocompute.start.astimezone(pytz.utc)
Expand Down