diff --git a/apps/utils/keystone.py b/apps/utils/keystone.py index 644432f..dc080ad 100644 --- a/apps/utils/keystone.py +++ b/apps/utils/keystone.py @@ -18,18 +18,15 @@ def get_request_allocations(session: KeystoneClient, request_pk: int) -> dict: """Get All Allocation information from keystone for a given request""" - return session.http_get(session.schema.allocations, {'request': request_pk}).json() + return session.retrieve_allocation(filters={'request': request_pk}) def get_active_requests(session: KeystoneClient, group_pk: int) -> [dict]: """Get all active AllocationRequest information from keystone for a given group""" today = date.today().isoformat() - return session.http_get(session.schema.requests, - {'group': group_pk, - 'status': 'AP', - 'active__lte': today, - 'expire__gt': today}).json() + return session.retrieve_request( + filters={'group': group_pk, 'status': 'AP', 'active__lte': today, 'expire__gt': today}) def get_researchgroup_id(session: KeystoneClient, account_name: str) -> int: @@ -37,7 +34,7 @@ def get_researchgroup_id(session: KeystoneClient, account_name: str) -> int: # Attempt to get the primary key for the ResearchGroup try: - keystone_group_id = session.http_get(session.schema.research_groups, {'name': account_name}).json()[0]['id'] + keystone_group_id = session.retrieve_research_group(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") @@ -63,18 +60,15 @@ def get_most_recent_expired_request(session: KeystoneClient, group_pk: int) -> [ """Get the single most recently expired AllocationRequest information from keystone for a given group""" today = date.today().isoformat() - return session.http_get(session.schema.requests, - {'group': group_pk, - 'status': 'AP', - 'ordering': '-expire', - 'expire__lte': today}).json()[0] + return session.retrieve_request( + filters={'group': group_pk, 'status': 'AP', 'ordering': '-expire', 'expire__lte': today})[0] def get_enabled_cluster_ids(session: KeystoneClient) -> dict(): """Get the list of enabled clusters defined in Keystone along with their IDs""" clusters = {} - for cluster in session.http_get(session.schema.clusters, {'enabled': True}).json(): + for cluster in session.retrieve_cluster(filters={'enabled': True}): clusters[cluster['id']] = cluster['name'] return clusters diff --git a/pyproject.toml b/pyproject.toml index 0a0529b..9b38ba0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ crc-usage = "apps.crc_usage:CrcUsage.execute" python = "^3.9.0" requests = "^2.31.0" prettytable = "^3.10.0" -keystone-api-client = "^0.3.16" +keystone-api-client = "^0.3.21" [tool.poetry.group.tests] optional = true