Home | History | Annotate | Download | only in platform
      1 # Copyright 2014 The Chromium 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 import logging
      5 
      6 from telemetry.core import cros_interface
      7 from telemetry.core import platform
      8 from telemetry.internal.platform import device
      9 
     10 
     11 class CrOSDevice(device.Device):
     12   def __init__(self, host_name, ssh_port, ssh_identity, is_local):
     13     super(CrOSDevice, self).__init__(
     14         name='ChromeOs with host %s' % host_name or 'localhost',
     15         guid='cros:%s' % host_name or 'localhost')
     16     self._host_name = host_name
     17     self._ssh_port = ssh_port
     18     self._ssh_identity = ssh_identity
     19     self._is_local = is_local
     20 
     21   @classmethod
     22   def GetAllConnectedDevices(cls, blacklist):
     23     return []
     24 
     25   @property
     26   def host_name(self):
     27     return self._host_name
     28 
     29   @property
     30   def ssh_port(self):
     31     return self._ssh_port
     32 
     33   @property
     34   def ssh_identity(self):
     35     return self._ssh_identity
     36 
     37   @property
     38   def is_local(self):
     39     return self._is_local
     40 
     41 
     42 def IsRunningOnCrOS():
     43   return platform.GetHostPlatform().GetOSName() == 'chromeos'
     44 
     45 
     46 def FindAllAvailableDevices(options):
     47   """Returns a list of available device types."""
     48   use_ssh = options.cros_remote and cros_interface.HasSSH()
     49   if not use_ssh and not IsRunningOnCrOS():
     50     logging.debug('No --remote specified, and not running on ChromeOs.')
     51     return []
     52 
     53   return [CrOSDevice(options.cros_remote, options.cros_remote_ssh_port,
     54                      options.cros_ssh_identity, not use_ssh)]
     55