Skip to content

Commit

Permalink
Fix referencing data section of schema (#255)
Browse files Browse the repository at this point in the history
* fix referencing data section of schema

* bump minimum version of keystone-client-api

* use retrieve method instead of http_get

* retrieve method returns JSON
  • Loading branch information
Comeani authored Aug 23, 2024
1 parent d830c63 commit cdd1626
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions apps/utils/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@
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:
"""Get the Researchgroup ID from keystone for the specified Slurm account"""

# 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")
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdd1626

Please sign in to comment.