Skip to content

Commit 5a0b508

Browse files
committed
change default account
1 parent 85cd4b0 commit 5a0b508

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

coldfront/plugins/slurmrest/utils.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
from slurm_rest_api_client import Client
99
from slurm_rest_api_client.api.slurm import slurm_v0043_delete_jobs
10-
from slurm_rest_api_client.api.slurmdb import slurmdb_v0043_get_accounts, slurmdb_v0043_post_associations
10+
from slurm_rest_api_client.api.slurmdb import (
11+
slurmdb_v0043_get_accounts,
12+
slurmdb_v0043_get_associations,
13+
slurmdb_v0043_post_associations,
14+
)
1115
from slurm_rest_api_client.models.v0043_account import V0043Account
1216
from slurm_rest_api_client.models.v0043_assoc import V0043Assoc
1317
from slurm_rest_api_client.models.v0043_assoc_max import V0043AssocMax
@@ -105,13 +109,12 @@ def delete_association_user_account(self, username: str, account: str, noop: boo
105109
logging.debug(f"deletion status: {status}")
106110
if jobs_delete_resp.errors:
107111
for error in jobs_delete_resp.errors:
108-
logging.warning(f"error deleting job: {error}")
112+
logging.error(f"error deleting job: {error}")
109113
raise RuntimeError(f"Could not delete jobs for user: {username} with account: {account}")
110114
else:
111115
raise ConnectionError(f"Could not delete jobs for user: {username} with account: {account}")
112116

113117
# set maxsubmit to 0 as root
114-
115118
max_submit_assoc: V0043Assoc = V0043Assoc(
116119
user=username,
117120
account=account,
@@ -121,4 +124,38 @@ def delete_association_user_account(self, username: str, account: str, noop: boo
121124
maxsubmit_set_resp = slurmdb_v0043_post_associations.sync(client=self.root_client, body=body_max_submit)
122125
if maxsubmit_set_resp:
123126
logger.info("resp")
127+
if maxsubmit_set_resp.errors:
128+
for error in maxsubmit_set_resp.errors:
129+
logging.error(f"error posting association: {error}")
130+
raise RuntimeError(f"Could not set maxsubmit=0 for user: {username} with account: {account}")
131+
else:
132+
raise ConnectionError(f"Could not set maxsubmit=0 for user: {username} with account: {account}")
133+
134+
default_assoc_get_resp = slurmdb_v0043_get_associations.sync(
135+
client=self.root_client, filter_to_only_defaults=str(True)
136+
)
137+
if not default_assoc_get_resp:
138+
raise ConnectionError(f"Could not get default association for user: {username}")
139+
if default_assoc_get_resp.errors:
140+
raise RuntimeError(f"Could not get default association for user: {username}")
141+
142+
default_account_for_this_user = default_assoc_get_resp.associations[0].account
143+
if default_account_for_this_user == account:
144+
logger.info(
145+
f"User: {username} has set the account: {account} as their default. Re-setting their default account."
146+
)
147+
# Assuming that everyone on the cluster is part of the account "users"!
148+
set_default_account_accoc: V0043Assoc = V0043Assoc(user=username, account="users", is_default=True)
149+
default_assoc_set_body: V0043OpenapiAssocsResp = V0043OpenapiAssocsResp(
150+
associations=[set_default_account_accoc]
151+
)
152+
153+
default_assoc_set_resp = slurmdb_v0043_post_associations.sync(
154+
client=self.root_client, body=default_assoc_set_body
155+
)
156+
if not default_assoc_set_resp:
157+
raise ConnectionError(f"Could not set default association for user: {username}")
158+
if default_assoc_set_resp.errors:
159+
raise RuntimeError(f"Could not set default association for user: {username}")
160+
124161
return

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ plugins = ["mypy_django_plugin.main"]
109109
django_settings_module = "coldfront.config.settings"
110110

111111
[tool.uv.sources]
112-
slurm-rest-api-client = { git = "https://github.com/NYU-RTS/rts-slurm-python-sdk", branch = "slimmer-cleaner-client-sdk" }
112+
slurm-rest-api-client = { git = "https://github.com/NYU-RTS/rts-slurm-python-sdk"}

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)