From b2e6500cc2d474ed0755922efbc074b16c1a01b0 Mon Sep 17 00:00:00 2001
From: payno <henri.payno@esrf.fr>
Date: Wed, 19 Mar 2025 08:49:24 +0100
Subject: [PATCH] utils: add 'get_partition_nodes' function

---
 src/sluurp/utils.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/sluurp/utils.py b/src/sluurp/utils.py
index 02ea885..e763c1e 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():
-- 
GitLab