Revision 16abfbc2 lib/utils.py

b/lib/utils.py
37 37
from ganeti import logger
38 38
from ganeti import errors
39 39

  
40

  
40 41
_locksheld = []
41 42
_re_shell_unquoted = re.compile('^[-.,=:/_+@A-Za-z0-9]+$')
42 43

  
......
782 783
  return ' '.join([ShellQuote(i) for i in args])
783 784

  
784 785

  
785
def _ParseIpOutput(output):
786
  """Parsing code for GetLocalIPAddresses().
787

  
788
  This function is split out, so we can unit test it.
789

  
790
  """
791
  re_ip = re.compile('^(\d+\.\d+\.\d+\.\d+)(?:/\d+)$')
792

  
793
  ips = []
794
  for line in output.splitlines(False):
795
    fields = line.split()
796
    if len(line) < 4:
797
      continue
798
    m = re_ip.match(fields[3])
799
    if m:
800
      ips.append(m.group(1))
801

  
802
  return ips
803

  
804

  
805
def GetLocalIPAddresses():
806
  """Gets a list of all local IP addresses.
807

  
808
  Should this break one day, a small Python module written in C could
809
  use the API call getifaddrs().
810

  
811
  """
812
  result = RunCmd(["ip", "-family", "inet", "-oneline", "addr", "show"])
813
  if result.failed:
814
    raise errors.OpExecError("Command '%s' failed, error: %s,"
815
      " output: %s" % (result.cmd, result.fail_reason, result.output))
816

  
817
  return _ParseIpOutput(result.output)
818

  
819 786

  
820
def TcpPing(source, target, port, timeout=10, live_port_needed=True):
787
def TcpPing(source, target, port, timeout=10, live_port_needed=False):
821 788
  """Simple ping implementation using TCP connect(2).
822 789

  
823 790
  Try to do a TCP connect(2) from the specified source IP to the specified

Also available in: Unified diff