|
8 | 8 | from slurm_rest_api_client import Client |
9 | 9 | from slurm_rest_api_client.api.slurm import slurm_v0043_delete_jobs |
10 | 10 | from slurm_rest_api_client.api.slurmdb import ( |
| 11 | + slurmdb_v0043_delete_account, |
11 | 12 | slurmdb_v0043_delete_association, |
12 | 13 | slurmdb_v0043_get_accounts, |
13 | 14 | slurmdb_v0043_get_associations, |
@@ -169,3 +170,24 @@ def delete_association_user_account(self, username: str, account: str, noop: boo |
169 | 170 | raise RuntimeError(f"Could not delete association for user: {username} and account: {account}") |
170 | 171 |
|
171 | 172 | return |
| 173 | + |
| 174 | + @retry( |
| 175 | + wait=wait_exponential(multiplier=2, min=2, max=10), |
| 176 | + stop=stop_after_attempt(3), |
| 177 | + retry=retry_if_not_exception_type(ConnectionError), |
| 178 | + before_sleep=before_sleep_log(logging.getLogger(__name__), logging.WARNING), |
| 179 | + ) |
| 180 | + def delete_slurm_account(self, account: str, noop: bool = False) -> None: |
| 181 | + if noop: |
| 182 | + logging.info(f"noop enabled: skip deleting acconut: {account}") |
| 183 | + return |
| 184 | + |
| 185 | + account_delete_resp = slurmdb_v0043_delete_account.sync(client=self.root_client, account_name=account) |
| 186 | + |
| 187 | + if not account_delete_resp: |
| 188 | + raise ConnectionError(f"Could not delete account: {account}") |
| 189 | + if account_delete_resp.errors: |
| 190 | + raise RuntimeError(f"Could not delete account: {account}") |
| 191 | + for account_removed in account_delete_resp.removed_accounts: |
| 192 | + logging.info(f"Removed SLURM account: {account_removed}") |
| 193 | + return |
0 commit comments