Commit e9e26bb3 authored by Iustin Pop's avatar Iustin Pop
Browse files

Enhance cli.GetOnlineNodes query/filtering

This patch allows GetOnlineNodes to return the secondary IPs instead of
the node names, and to provide filtering of the master node (required to
be done in this function in case we return the secondary IPs).
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 25a8792c
......@@ -1883,7 +1883,8 @@ def ParseTimespec(value):
return value
def GetOnlineNodes(nodes, cl=None, nowarn=False):
def GetOnlineNodes(nodes, cl=None, nowarn=False, secondary_ips=False,
"""Returns the names of online nodes.
This function will also log a warning on stderr with the names of
......@@ -1896,17 +1897,36 @@ def GetOnlineNodes(nodes, cl=None, nowarn=False):
@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
@type secondary_ips: boolean
@param secondary_ips: if True, return the secondary IPs instead of the
names, useful for doing network traffic over the replication interface
(if any)
@type filter_master: boolean
@param filter_master: if True, do not return the master node in the list
(useful in coordination with secondary_ips where we cannot check our
node name against the list)
if cl is None:
cl = GetClient()
result = cl.QueryNodes(names=nodes, fields=["name", "offline"],
if secondary_ips:
name_idx = 2
name_idx = 0
if filter_master:
master_node = cl.QueryConfigValues(["master_node"])[0]
filter_fn = lambda x: x != master_node
filter_fn = lambda _: True
result = cl.QueryNodes(names=nodes, fields=["name", "offline", "sip"],
offline = [row[0] for row in result if row[1]]
if offline and not nowarn:
ToStderr("Note: skipping offline node(s): %s" % utils.CommaJoin(offline))
return [row[0] for row in result if not row[1]]
return [row[name_idx] for row in result if not row[1] and filter_fn(row[0])]
def _ToStream(stream, txt, *args):
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