diff --git a/lib/cli.py b/lib/cli.py index dea707801516f634b974d656863b269a47e2914b..0534bc7ce8e49de16076f38f9822ccabf94cffd4 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -53,6 +53,7 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", "ValidateBeParams", "ToStderr", "ToStdout", "UsesRPC", + "GetOnlineNodes", ] @@ -921,6 +922,33 @@ def ParseTimespec(value): return value +def GetOnlineNodes(nodes, cl=None, nowarn=False): + """Returns the names of online nodes. + + This function will also log a warning on stderr with the names of + the online nodes. + + @param nodes: if not empty, use only this subset of nodes (minus the + offline ones) + @param cl: if not None, luxi client to use + @type nowarn: boolean + @param nowarn: by default, this function will output a note with the + offline nodes that are skipped; if this parameter is True the + note is not displayed + + """ + if cl is None: + cl = GetClient() + + op = opcodes.OpQueryNodes(output_fields=["name", "offline"], + names=nodes) + result = SubmitOpCode(op, cl=cl) + offline = [row[0] for row in result if row[1]] + if offline and not nowarn: + ToStderr("Note: skipping offline node(s): %s" % ", ".join(offline)) + return [row[0] for row in result if not row[1]] + + def _ToStream(stream, txt, *args): """Write a message to a stream, bypassing the logging system diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 7f2382194bad82ad10dcd3b28a64462a55c0b782..09c1eb261c20350149f8746183ce5ba2f92cd2fe 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -288,8 +288,8 @@ def ClusterCopyFile(opts, args): cluster_name = cl.QueryConfigValues(["cluster_name"])[0] - op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) - results = [row[0] for row in SubmitOpCode(op, cl=cl) if row[0] != myname] + results = GetOnlineNodes(nodes=opts.nodes, cl=cl) + results = [name for name in results if name != myname] srun = ssh.SshRunner(cluster_name=cluster_name) for node in results: @@ -312,8 +312,8 @@ def RunClusterCommand(opts, args): cl = GetClient() command = " ".join(args) - op = opcodes.OpQueryNodes(output_fields=["name"], names=opts.nodes) - nodes = [row[0] for row in SubmitOpCode(op, cl=cl)] + + nodes = GetOnlineNodes(nodes=opts.nodes, cl=cl) cluster_name, master_node = cl.QueryConfigValues(["cluster_name", "master_node"])