def transfer_to(self, local_path, remote_path, timeout_secs, recursive=False): """ Transfer 'local_path' to 'remote_path' on _host. 'timeout_secs' specifies a timeout on the transfer. 'recursive' specifies whether the transfer is recursive or not. Returns True on success, else False on failure or a timeout. """ if recursive: opts = self.__base_scp_opts + " -r" else: opts = self.__base_scp_opts cmd = "scp %s %s '%s@%s:%s'" % \ (opts, local_path, self.__user, self.__host, remote_path) log.debug("Transferring %s to %s:%s to using %s", local_path, self.__host, remote_path, cmd) status, _, _ = CurieUtil.timed_command(cmd, timeout_secs) return status == 0
def __execute_command(self, cmd): """ Executes 'cmd' via ipmitool 'self.__ipmitool_abspath' using '__flags'. Returns: (tuple): (rv, stdout, stderr) Raises: CurieException on bad input or failure to execute the command. """ if isinstance(cmd, basestring): cmd = cmd.split(" ") if not isinstance(cmd, list): raise CurieException( CurieError.kInternalError, "'cmd' must be of type list or str, not '%s'" % cmd.__class__.__name__) generated_cmd = [] map(generated_cmd.extend, [[self.__ipmitool_abspath], self.__get_flag_list(redacted=False), cmd]) redacted_cmd = [] map(redacted_cmd.extend, [[self.__ipmitool_abspath], self.__get_flag_list(redacted=True), cmd]) log.info("Executing IPMI command:\n\t'%s'", " ".join(redacted_cmd)) rv, stdout, stderr = CurieUtil.timed_command( " ".join(generated_cmd), timeout_secs=60, formatted_cmd=" ".join(redacted_cmd)) cmd_output = "rv=%s\nstdout=%s\nstderr=%s" % (rv, stdout, stderr) if rv < 0: raise CurieException( CurieError.kInternalError, "Failed to execute command: '%s': %s" % (redacted_cmd, cmd_output)) log.debug(cmd_output) return (rv, stdout, stderr)