示例#1
0
    def remote_login(self, nic_index=0, timeout=10):
        """
        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: kvm_spawn object on success and None on failure.
        """
        username = self.params.get("username", "")
        password = self.params.get("password", "")
        prompt = self.params.get("shell_prompt", "[\#\$]")
        client = self.params.get("shell_client")
        address = self.get_address(nic_index)
        port = self.get_port(int(self.params.get("shell_port")))

        if not address or not port:
            logging.debug("IP address or port unavailable")
            return None

        if client == "ssh":
            session = kvm_utils.ssh(address, port, username, password, prompt, timeout)
        elif client == "telnet":
            session = kvm_utils.telnet(address, port, username, password, prompt, timeout)
        elif client == "nc":
            session = kvm_utils.netcat(address, port, username, password, prompt, timeout)

        if session:
            session.set_status_test_command(self.params.get("status_test_" "command", ""))
        return session
示例#2
0
文件: kvm_vm.py 项目: yochow/autotest
    def ssh_login(self, timeout=10):
        """
        Log into the guest via SSH/Telnet.
        If timeout expires while waiting for output from the guest (e.g. a
        password prompt or a shell prompt) -- fail.

        @param timeout: Time (seconds) before giving up logging into the
                guest.
        @return: kvm_spawn object on success and None on failure.
        """
        username = self.params.get("username", "")
        password = self.params.get("password", "")
        prompt = self.params.get("ssh_prompt", "[\#\$]")
        use_telnet = self.params.get("use_telnet") == "yes"
        address = self.get_address()
        port = self.get_port(int(self.params.get("ssh_port")))
        if not port:
            return None

        if use_telnet:
            session = kvm_utils.telnet(address, port, username, password,
                                       prompt, timeout)
        else:
            session = kvm_utils.ssh(address, port, username, password,
                                    prompt, timeout)
        if session:
            session.set_status_test_command(self.params.get("ssh_status_test_"
                                                            "command", ""))
        return session