From 2c2bba7bc0084c1272bfc66ee564f3a278f2f9c0 Mon Sep 17 00:00:00 2001 From: Daniel Perrefort Date: Thu, 24 Oct 2024 14:37:55 -0400 Subject: [PATCH] Upgrade wrappers to use teams instead of groups (#269) Start upgrading from groups to teams --- apps/crc_proposal_end.py | 6 +++--- apps/crc_sus.py | 2 +- apps/crc_usage.py | 2 +- apps/utils/keystone.py | 22 +++++++++++----------- pyproject.toml | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/crc_proposal_end.py b/apps/crc_proposal_end.py index e2fe248..224fa86 100755 --- a/apps/crc_proposal_end.py +++ b/apps/crc_proposal_end.py @@ -36,13 +36,13 @@ def app_logic(self, args: Namespace) -> None: keystone_session = KeystoneClient(url=KEYSTONE_URL) keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) - group_id = get_researchgroup_id(keystone_session, args.account) - alloc_requests = get_active_requests(keystone_session, group_id) + team_id = get_team_id(keystone_session, args.account) + alloc_requests = get_active_requests(keystone_session, team_id) if not alloc_requests: print(f"\033[91m\033[1mNo active allocation information found in accounting system for '{args.account}'!\n") print("Showing end date for most recently expired Resource Allocation Request:\033[0m") - alloc_requests = [get_most_recent_expired_request(keystone_session, group_id)] + alloc_requests = [get_most_recent_expired_request(keystone_session, team_id)] for request in alloc_requests: print(f"'{request['title']}' ends on {request['expire']} ") diff --git a/apps/crc_sus.py b/apps/crc_sus.py index 6de2fcf..a25d478 100755 --- a/apps/crc_sus.py +++ b/apps/crc_sus.py @@ -61,7 +61,7 @@ def app_logic(self, args: Namespace) -> None: keystone_session = KeystoneClient(url=KEYSTONE_URL) keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) - group_id = get_researchgroup_id(keystone_session, args.account) + group_id = get_team_id(keystone_session, args.account) alloc_requests = get_active_requests(keystone_session, group_id) if not alloc_requests: diff --git a/apps/crc_usage.py b/apps/crc_usage.py index 4281497..0c37a30 100755 --- a/apps/crc_usage.py +++ b/apps/crc_usage.py @@ -101,7 +101,7 @@ def app_logic(self, args: Namespace) -> None: keystone_session.login(username=os.environ["USER"], password=getpass("Please enter your CRC login password:\n")) # Gather AllocationRequests from Keystone - group_id = get_researchgroup_id(keystone_session, args.account) + group_id = get_team_id(keystone_session, args.account) alloc_requests = get_active_requests(keystone_session, group_id) if not alloc_requests: diff --git a/apps/utils/keystone.py b/apps/utils/keystone.py index dc080ad..7da135d 100644 --- a/apps/utils/keystone.py +++ b/apps/utils/keystone.py @@ -21,26 +21,26 @@ def get_request_allocations(session: KeystoneClient, request_pk: int) -> dict: 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""" +def get_active_requests(session: KeystoneClient, team_pk: int) -> [dict]: + """Get all active AllocationRequest information from keystone for a given team""" today = date.today().isoformat() return session.retrieve_request( - filters={'group': group_pk, 'status': 'AP', 'active__lte': today, 'expire__gt': today}) + filters={'team': team_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""" +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 ResearchGroup + # Attempt to get the primary key for the Team try: - keystone_group_id = session.retrieve_research_group(filters={'name': account_name})[0]['id'] + 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_group_id + return keystone_team_id def get_earliest_startdate(alloc_requests: [dict]) -> date: @@ -56,12 +56,12 @@ def get_earliest_startdate(alloc_requests: [dict]) -> date: return max(earliest_date, RAWUSAGE_RESET_DATE) -def get_most_recent_expired_request(session: KeystoneClient, group_pk: int) -> [dict]: - """Get the single most recently expired AllocationRequest information from keystone for a given group""" +def get_most_recent_expired_request(session: KeystoneClient, team_pk: int) -> [dict]: + """Get the single most recently expired AllocationRequest information from keystone for a given team""" today = date.today().isoformat() return session.retrieve_request( - filters={'group': group_pk, 'status': 'AP', 'ordering': '-expire', 'expire__lte': today})[0] + filters={'team': team_pk, 'status': 'AP', 'ordering': '-expire', 'expire__lte': today})[0] def get_enabled_cluster_ids(session: KeystoneClient) -> dict(): diff --git a/pyproject.toml b/pyproject.toml index 32dab2f..83f5ce8 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.4.0" +keystone-api-client = "^0.5.0" [tool.poetry.group.tests] optional = true