Revision e9e26bb3 lib/cli.py

b/lib/cli.py
1883 1883
  return value
1884 1884

  
1885 1885

  
1886
def GetOnlineNodes(nodes, cl=None, nowarn=False):
1886
def GetOnlineNodes(nodes, cl=None, nowarn=False, secondary_ips=False,
1887
                   filter_master=False):
1887 1888
  """Returns the names of online nodes.
1888 1889

  
1889 1890
  This function will also log a warning on stderr with the names of
......
1896 1897
  @param nowarn: by default, this function will output a note with the
1897 1898
      offline nodes that are skipped; if this parameter is True the
1898 1899
      note is not displayed
1900
  @type secondary_ips: boolean
1901
  @param secondary_ips: if True, return the secondary IPs instead of the
1902
      names, useful for doing network traffic over the replication interface
1903
      (if any)
1904
  @type filter_master: boolean
1905
  @param filter_master: if True, do not return the master node in the list
1906
      (useful in coordination with secondary_ips where we cannot check our
1907
      node name against the list)
1899 1908

  
1900 1909
  """
1901 1910
  if cl is None:
1902 1911
    cl = GetClient()
1903 1912

  
1904
  result = cl.QueryNodes(names=nodes, fields=["name", "offline"],
1913
  if secondary_ips:
1914
    name_idx = 2
1915
  else:
1916
    name_idx = 0
1917

  
1918
  if filter_master:
1919
    master_node = cl.QueryConfigValues(["master_node"])[0]
1920
    filter_fn = lambda x: x != master_node
1921
  else:
1922
    filter_fn = lambda _: True
1923

  
1924
  result = cl.QueryNodes(names=nodes, fields=["name", "offline", "sip"],
1905 1925
                         use_locking=False)
1906 1926
  offline = [row[0] for row in result if row[1]]
1907 1927
  if offline and not nowarn:
1908 1928
    ToStderr("Note: skipping offline node(s): %s" % utils.CommaJoin(offline))
1909
  return [row[0] for row in result if not row[1]]
1929
  return [row[name_idx] for row in result if not row[1] and filter_fn(row[0])]
1910 1930

  
1911 1931

  
1912 1932
def _ToStream(stream, txt, *args):

Also available in: Unified diff