def execute(self, command, timeout, environment=(), user="******", verbose=False): """ Runs a command on the device and returns log and errorlevel. """ return Ssh.execute(dev_ip=self._registered_lease, timeout=timeout, user=user, environment=environment, command=command, verbose=verbose)
def _get_model_and_type(cls, dev_ip): """ Tries to assess the model and type of the device. """ cpuinfo = Ssh.execute(dev_ip=dev_ip, command=("cat", "/proc/cpuinfo")) if cpuinfo: return cls._devices_catalog.get_model_and_type_by_device(cpuinfo) return [None, None]
def _by_ip_is_responsive(cls, dev_ip): """ Check if the device is in service mode. """ logging.debug("Trying to ssh into {0}.".format(dev_ip)) result = Ssh.execute(dev_ip=dev_ip, command=("echo", "$?"), timeout=cls._SSH_SHORT_GENERIC_TIMEOUT, ) logging.debug("result: {0}".format(result)) if (result is None) or (result.returncode is not 0): logging.debug("Ssh failed.") else: logging.debug("Ssh successful.") return (result is not None) and (result.returncode is 0)
def init_class(cls, init_data): """ Initializer for class variables and parent class. """ try: logging.debug("PCDevice class init_data: {0}". format(init_data)) cls._leases_file_name = init_data["leases_file_name"] cls._root_partition = init_data["root_partition"] cls._service_mode_name = init_data["service_mode"] cls._test_mode_name = init_data["test_mode"] cls._registered_lease = None return Ssh.init() and Scp.init() except KeyError as error: logging.critical("Error initializing PC Device Class {0}." .format(error)) return False
def _by_ip_is_in_mode(cls, dev_ip, mode): """ Check if the device with given ip is responsive to ssh and in the specified mode. """ logging.debug("Trying to ssh into {0} to test the mode.".format(dev_ip)) retval = Ssh.execute(dev_ip=dev_ip, command=("cat", "/proc/version", "|", "grep", mode["name"]), timeout=cls._SSH_SHORT_GENERIC_TIMEOUT, ) if retval is None or retval.returncode is not 0: logging.debug("Ssh failed.") elif mode["name"] not in retval.stdoutdata: logging.debug("Device not in \"{0}\" mode.".format(mode["name"])) else: logging.debug("Device in \"{0}\" mode.".format(mode["name"])) return retval is not None and \ retval.returncode is 0 and \ mode["name"] in retval.stdoutdata