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