diff --git a/src/sluurp/utils.py b/src/sluurp/utils.py index 02ea88590ebfa4542c8a6b915a8c540ce0ff448d..e763c1eb333d7192ece9e58837dd665a8af744ff 100644 --- a/src/sluurp/utils.py +++ b/src/sluurp/utils.py @@ -83,6 +83,28 @@ def get_partition_walltime(partition: str) -> dict[str, str]: } +def get_partition_nodes(partition: str) -> tuple: + """ + For a given partition return the available nodes + """ + process = SubProcessCommand(command=f"sinfo --partition={partition} --Node") + try: + res = process.run() + except Exception: + return None, None + + # treat output string + res = res.split("\n") + if len(res) < 1: + return tuple() + else: + # pop first list (HEADER) + res = res[1:] + return tuple( + filter(None, [line.split(" ")[0] for line in res]) # filter empty strings + ) + + class SubProcessCommand: def __init__(self, command, platform="Linux"): if platform != _platform_mod.system():