Commit 4040a784 authored by Iustin Pop's avatar Iustin Pop
Browse files

Skip offline nodes in gnt-cluster commands

This patch makes gnt-cluster copyfile and command skip the offline
nodes.

Reviwed-by: ultrotter, imsnah
parent 5c22d16e
......@@ -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
......
......@@ -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"])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment