Add completing to states available

This commit is contained in:
Benoît Seignovert 2024-03-07 15:27:22 +01:00
parent ae9ac12918
commit c4c8fa33aa
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 12 additions and 6 deletions

View file

@ -8,6 +8,12 @@ from itertools import groupby
from operator import attrgetter
from pathlib import Path
STATES_AVAILABLE = (
'idle',
'mixed',
'completing',
)
@dataclass
class SlurmCpu:
@ -150,7 +156,7 @@ def sinfo_reader(result: str) -> list:
return [SlurmNode(*re.findall('.{20}', node)) for node in result.splitlines()]
def sinfo_filter(resources: list, with_states=('idle', 'mixed')) -> dict:
def sinfo_filter(resources: list, with_states=STATES_AVAILABLE) -> dict:
"""SLURM SINFO filtered resources available with a given state(s).
Grouped by cluster and partition names.
@ -172,13 +178,13 @@ def sinfo_filter(resources: list, with_states=('idle', 'mixed')) -> dict:
return {cluster.name: cluster for cluster in clusters if cluster}
def sinfo_from_file(fname, with_states=('idle', 'mixed')) -> dict:
def sinfo_from_file(fname, with_states=STATES_AVAILABLE) -> dict:
"""SLURM SINFO resources available from a given file."""
content = Path(fname).read_text()
return sinfo_filter(sinfo_reader(content), with_states=with_states)
def sinfo(username: str = None, with_states=('idle', 'mixed')) -> dict:
def sinfo(username: str = None, with_states=STATES_AVAILABLE) -> dict:
"""SLURM SINFO resources available for a given user."""
return sinfo_filter(sinfo_reader(sinfo_run(username=username)), with_states=with_states)