Skip to content

Commit

Permalink
adjust utils functions to use search and order where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Comeani committed Dec 12, 2024
1 parent 0c31f9d commit df79d86
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions apps/utils/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,13 @@ def get_request_allocations(session: KeystoneClient, request_pk: int) -> dict:
return session.retrieve_allocation(filters={'request': request_pk})


def get_active_requests(session: KeystoneClient, team_pk: int) -> [dict]:
def get_active_requests(session: KeystoneClient, account_name: str) -> [dict]:
"""Get all active AllocationRequest information from keystone for a given team"""

today = date.today().isoformat()
return session.retrieve_request(
filters={'team': team_pk, 'status': 'AP', 'active__lte': today, 'expire__gt': today})


def get_team_id(session: KeystoneClient, account_name: str) -> int:
"""Get the Team ID from keystone for the specified Slurm account"""

# Attempt to get the primary key for the Team
try:
keystone_team_id = session.retrieve_team(filters={'name': account_name})[0]['id']
except IndexError:
print(f"No Slurm Account found in the accounting system for '{account_name}'. \n"
f"Please submit a ticket to the CRC team to ensure your allocation was properly configured")
exit()

return keystone_team_id
search=account_name,
filters={'status': 'AP', 'active__lte': today, 'expire__gt': today})


def get_earliest_startdate(alloc_requests: [dict]) -> date:
Expand All @@ -56,12 +43,14 @@ def get_earliest_startdate(alloc_requests: [dict]) -> date:
return max(earliest_date, RAWUSAGE_RESET_DATE)


def get_most_recent_expired_request(session: KeystoneClient, team_pk: int) -> [dict]:
def get_most_recent_expired_request(session: KeystoneClient, account_name: str) -> [dict]:
"""Get the single most recently expired AllocationRequest information from keystone for a given team"""

today = date.today().isoformat()
return session.retrieve_request(
filters={'team': team_pk, 'status': 'AP', 'ordering': '-expire', 'expire__lte': today})[0]
search=account_name,
order='-expire',
filters={'status': 'AP', 'expire__lte': today})[0]


def get_enabled_cluster_ids(session: KeystoneClient) -> dict():
Expand All @@ -75,10 +64,10 @@ def get_enabled_cluster_ids(session: KeystoneClient) -> dict():


def get_per_cluster_totals(session: KeystoneClient,
alloc_requests: [dict],
clusters: dict,
per_request: bool = False
) -> dict:
alloc_requests: [dict],
clusters: dict,
per_request: bool = False
) -> dict:
"""Gather the awarded totals across the given requests on each cluster into a dictionary"""

per_cluster_totals = {}
Expand Down

0 comments on commit df79d86

Please sign in to comment.