From 7aed3382862bad54573106b5cd91179710af5a8a Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Thu, 7 Feb 2008 19:36:31 +0000
Subject: [PATCH] In sched/wiki2: accept hostname expression as input for
 GETNODES command.

---
 NEWS                                |  3 ++-
 src/plugins/sched/wiki/get_nodes.c  |  5 ++++
 src/plugins/sched/wiki2/get_nodes.c | 38 ++++++++++++++++++-----------
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index aedb5ec0979..eafff180d58 100644
--- a/NEWS
+++ b/NEWS
@@ -10,8 +10,9 @@ documents those changes that are of interest to users and admins.
     changes in real time changes in operating system. These values are reported
     by "scontrol show node" plus the sched/wiki and sched/wiki2 plugins for Maui
     and Moab respectively.
- -- In sched/wiki and sched/wiki2, add HostFormat and HidePartitionJobs to 
+ -- In sched/wiki and sched/wiki2: add HostFormat and HidePartitionJobs to 
     "scontrol show config" SCHEDULER_CONF output.
+ -- In sched/wiki2: accept hostname expression as input for GETNODES command.
  
 * Changes in SLURM 1.3.0-pre9
 =============================
diff --git a/src/plugins/sched/wiki/get_nodes.c b/src/plugins/sched/wiki/get_nodes.c
index ab49960b39b..45fa3b6550c 100644
--- a/src/plugins/sched/wiki/get_nodes.c
+++ b/src/plugins/sched/wiki/get_nodes.c
@@ -107,6 +107,11 @@ extern int	get_nodes(char *cmd_ptr, int *err_code, char **err_msg)
 		node_name = strtok_r(tmp_char, ":", &tmp2_char);
 		while (node_name) {
 			node_ptr = find_node_record(node_name);
+			if (node_ptr == NULL) {
+				error("sched/wiki2: bad hostname %s",
+				      node_name);
+				continue;
+			}
 			tmp_buf = _dump_node(node_ptr, state_info);
 			if (node_rec_cnt > 0)
 				xstrcat(buf, "#");
diff --git a/src/plugins/sched/wiki2/get_nodes.c b/src/plugins/sched/wiki2/get_nodes.c
index c85efe28cce..408dd533a86 100644
--- a/src/plugins/sched/wiki2/get_nodes.c
+++ b/src/plugins/sched/wiki2/get_nodes.c
@@ -112,21 +112,31 @@ extern int	get_nodes(char *cmd_ptr, int *err_code, char **err_msg)
 		buf = _dump_all_nodes(&node_rec_cnt, state_info);
 	} else {
 		struct node_record *node_ptr = NULL;
-		char *node_name = NULL, *tmp2_char = NULL;
-
-		node_name = strtok_r(tmp_char, ":", &tmp2_char);
-		while (node_name) {
-			node_ptr = find_node_record(node_name);
-			if (!node_ptr)
-				continue;
-			tmp_buf = _dump_node(node_ptr, NULL, state_info);
-			if (node_rec_cnt > 0)
-				xstrcat(buf, "#");
-			xstrcat(buf, tmp_buf);
-			xfree(tmp_buf);
-			node_rec_cnt++;
-			node_name = strtok_r(NULL, ":", &tmp2_char);
+		char *node_name, *slurm_hosts;
+		int node_cnt;
+		hostset_t slurm_hostset;
+
+		slurm_hosts = moab2slurm_task_list(tmp_char, &node_cnt);
+		if ((slurm_hostset = hostset_create(slurm_hosts))) {
+			while ((node_name = hostset_shift(slurm_hostset))) {
+				node_ptr = find_node_record(node_name);
+				if (node_ptr == NULL) {
+					error("sched/wiki2: bad hostname %s", 
+					      node_name);
+					continue;
+				}
+				tmp_buf = _dump_node(node_ptr, NULL, state_info);
+				if (node_rec_cnt > 0)
+					xstrcat(buf, "#");
+				xstrcat(buf, tmp_buf);
+				xfree(tmp_buf);
+				node_rec_cnt++;
+			}
+			hostset_destroy(slurm_hostset);
+		} else {
+			error("hostset_create(%s): %m", slurm_hosts);
 		}
+		xfree(slurm_hosts);
 	}
 	unlock_slurmctld(node_read_lock);
 
-- 
GitLab