def login(self, nic_index=0, timeout=LOGIN_TIMEOUT, username=None, password=None): """ Log into the guest via SSH/Telnet/Netcat. If timeout expires while waiting for output from the guest (e.g. a password prompt or a shell prompt) -- fail. :param nic_index: The index of the NIC to connect to. :param timeout: Time (seconds) before giving up logging into the guest. :return: A ShellSession object. """ error.context("logging into '%s'" % self.name) if not username: username = self.params.get("username", "") if not password: password = self.params.get("password", "") prompt = self.params.get("shell_prompt", "[\#\$]") linesep = eval("'%s'" % self.params.get("shell_linesep", r"\n")) client = self.params.get("shell_client") neigh_attach_if = "" address = self.get_address(nic_index) if address and address.lower().startswith("fe80"): neigh_attach_if = utils_net.get_neigh_attch_interface(address) port = self.get_port(int(self.params.get("shell_port"))) log_filename = ("session-%s-%s.log" % (self.name, utils_misc.generate_random_string(4))) session = remote.remote_login(client, address, port, username, password, prompt, linesep, log_filename, timeout, interface=neigh_attach_if) session.set_status_test_command(self.params.get("status_test_command", "")) self.remote_sessions.append(session) return session
def copy_files_from(self, guest_path, host_path, nic_index=0, limit="", verbose=False, timeout=COPY_FILES_TIMEOUT, username=None, password=None): """ Transfer files from the guest. :param host_path: Guest path :param guest_path: Host path :param nic_index: The index of the NIC to connect to. :param limit: Speed limit of file transfer. :param verbose: If True, log some stats using logging.debug (RSS only) :param timeout: Time (seconds) before giving up on doing the remote copy. """ error.context("receiving file(s) from '%s'" % self.name) if not username: username = self.params.get("username", "") if not password: password = self.params.get("password", "") client = self.params.get("file_transfer_client") address = self.get_address(nic_index) neigh_attach_if = "" if address.lower().startswith("fe80"): neigh_attach_if = utils_net.get_neigh_attch_interface(address) port = self.get_port(int(self.params.get("file_transfer_port"))) log_filename = ("transfer-%s-from-%s-%s.log" % (self.name, address, utils_misc.generate_random_string(4))) remote.copy_files_from(address, client, username, password, port, guest_path, host_path, limit, log_filename, verbose, timeout, interface=neigh_attach_if) utils_misc.close_log_file(log_filename)