Add SLURM gres extraction from resources

This commit is contained in:
Benoît Seignovert 2024-02-20 11:16:53 +01:00
parent 21935f15f5
commit 05be86da07
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 23 additions and 0 deletions

View file

@ -181,3 +181,15 @@ def sinfo_from_file(fname, with_states=('idle', 'mixed')) -> dict:
def sinfo(username: str = None, with_states=('idle', 'mixed')) -> dict: def sinfo(username: str = None, with_states=('idle', 'mixed')) -> dict:
"""SLURM SINFO resources available for a given user.""" """SLURM SINFO resources available for a given user."""
return sinfo_filter(sinfo_reader(sinfo_run(username=username)), with_states=with_states) return sinfo_filter(sinfo_reader(sinfo_run(username=username)), with_states=with_states)
def gres(resources: dict) -> list:
"""List SLURM GPU resources."""
return sorted(
{
node.gpu.name
for cluster in resources.values()
for partition in cluster
for node in partition
}
)

View file

@ -8,6 +8,7 @@ from glicid_spawner.slurm import (
SlurmGpu, SlurmGpu,
SlurmNode, SlurmNode,
SlurmPartition, SlurmPartition,
gres,
sinfo, sinfo,
sinfo_filter, sinfo_filter,
sinfo_from_file, sinfo_from_file,
@ -242,3 +243,13 @@ def test_slurm_sinfo_resources(monkeypatch):
assert isinstance(cnode, SlurmNode) assert isinstance(cnode, SlurmNode)
assert cnode == 'cnode001' assert cnode == 'cnode001'
def test_slurm_gres():
"""Test SLURM GPU resources extraction."""
resources = sinfo_from_file(SINFO_FILE, with_states=('idle', 'idle~', 'mixed', 'allocated'))
gpus = gres(resources)
# Sorted and without duplicates
assert gpus == ['A100', 'A40', 'None', 'P100', 'T4']