• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4"""Utilities relating to machine-specific functions."""
5
6from __future__ import print_function
7
8from cros_utils import command_executer
9
10
11def MachineIsPingable(machine, logging_level='average'):
12  """Checks to see if a machine is responding to 'ping'.
13
14  Args:
15    machine: String containing the name or ip address of the machine to check.
16    logging_level: The logging level with which to initialize the
17      command_executer (from command_executor.LOG_LEVEL enum list).
18
19  Returns:
20    Boolean indicating whether machine is responding to ping or not.
21  """
22  ce = command_executer.GetCommandExecuter(log_level=logging_level)
23  cmd = 'ping -c 1 -w 3 %s' % machine
24  status = ce.RunCommand(cmd)
25  return status == 0
26