Skip to content

Commit

Permalink
Upgrade wrappers to use teams instead of groups (#269)
Browse files Browse the repository at this point in the history
Start upgrading from groups to teams
  • Loading branch information
djperrefort authored Oct 24, 2024
1 parent d85c6bc commit 2c2bba7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions apps/crc_proposal_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']} ")
2 changes: 1 addition & 1 deletion apps/crc_sus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion apps/crc_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions apps/utils/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
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.4.0"
keystone-api-client = "^0.5.0"

[tool.poetry.group.tests]
optional = true
Expand Down

0 comments on commit 2c2bba7

Please sign in to comment.