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