當前位置: 首頁>>代碼示例>>Python>>正文


Python ssh_exception.NoValidConnectionsError方法代碼示例

本文整理匯總了Python中paramiko.ssh_exception.NoValidConnectionsError方法的典型用法代碼示例。如果您正苦於以下問題:Python ssh_exception.NoValidConnectionsError方法的具體用法?Python ssh_exception.NoValidConnectionsError怎麽用?Python ssh_exception.NoValidConnectionsError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在paramiko.ssh_exception的用法示例。


在下文中一共展示了ssh_exception.NoValidConnectionsError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _connect

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def _connect(hostname, username, passwd, timeout, port=22):
    """
    get connect
    :param hostname:
    :param username:
    :param passwd:
    :param timeout:
    :param port:
    :return:
    """
    client = None
    try:
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostname, port, username, passwd, timeout=timeout)
    except ssh_exception.NoValidConnectionsError as e:
        print("username not exists")
    except ssh_exception.AuthenticationException as e:
        print("passwd not correct")
    except Exception as e:
        print("*** Caught exception: %s: %s" % (e.__class__, e))
        traceback.print_exc()
    return client 
開發者ID:baidu,項目名稱:CUP,代碼行數:25,代碼來源:expect.py

示例2: _sftp_connect

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def _sftp_connect(hostname, username, passwd, timeout, port=22):
    """
    get sftp connect
    :param hostname:
    :param username:
    :param passwd:
    :param timeout:
    :param port:
    :return:
    """
    client = None
    sftp = None
    try:
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect(hostname, port, username, passwd, timeout=timeout)
        sftp = paramiko.SFTPClient.from_transport(client.get_transport())
    except ssh_exception.NoValidConnectionsError as e:
        print("username not exists")
    except ssh_exception.AuthenticationException as e:
        print("passwd not correct")
    except Exception as e:
        print("*** Caught exception: %s: %s" % (e.__class__, e))
        traceback.print_exc()
    return client, sftp 
開發者ID:baidu,項目名稱:CUP,代碼行數:27,代碼來源:expect.py

示例3: create_conn_obj

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def create_conn_obj(self):
        self.conn = paramiko.SSHClient()
        self.conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        try:
            self.conn.connect(self.host, port=self.args.port)
        except AuthenticationException:
            return True
        except SSHException:
            return True
        except NoValidConnectionsError:
            return False
        except socket.error:
            return False 
開發者ID:byt3bl33d3r,項目名稱:CrackMapExec,代碼行數:16,代碼來源:ssh.py

示例4: wait_for_device

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def wait_for_device(self, countdown, poll_delay):

        dev = None

        # first we need to wait for the device to be 'reachable' via the API.
        # we'll use the probe error to detect if it is or not

        while not dev:
            msg = 'reload-countdown at: {} seconds'.format(countdown)
            self.post_device_status(message=msg, state='AWAIT-ONLINE')
            self.log.info(msg)

            try:
                dev = Device(self.target, user=self.user, passwd=self.passwd,
                             timeout=poll_delay)

            except AuthenticationException as e:
                self.log.info('Authentication exception reported: {} \n args: {}'.format(e, e.args))
                self.exit_results(results=dict(
                    ok=False,
                    error_type='login',
                    message='Unauthorized - check user/password'))

            except NoValidConnectionsError as e:
                countdown -= poll_delay
                if countdown <= 0:
                    self.exit_results(results=dict(
                        ok=False,
                        error_type='login',
                        message='Failed to connect to target %s within reload countdown' % self.target))

                time.sleep(poll_delay)

        self.dev = dev
        self.post_device_facts()

    # ##### -----------------------------------------------------------------------
    # #####
    # #####                           OS install process
    # #####
    # ##### ----------------------------------------------------------------------- 
開發者ID:Apstra,項目名稱:aeon-ztps,代碼行數:43,代碼來源:ubuntu_bootstrap.py

示例5: test_wait_for_device_no_valid_connections

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_wait_for_device_no_valid_connections(mock_dev, mock_exit, mock_time, cb_obj):
    mock_dev.side_effect = NoValidConnectionsError({'error': 'test error value'})
    with pytest.raises(SystemExit):
        cb_obj.wait_for_device(2, 1)
    mock_exit.assert_called_with(
        results={'ok': False,
                 'error_type': 'login',
                 'message': 'Failed to connect to target %s within reload countdown' % cb_obj.cli_args.target}
    ) 
開發者ID:Apstra,項目名稱:aeon-ztps,代碼行數:11,代碼來源:test_cumulus_bootstrap.py

示例6: test_wait_for_device_no_valid_connections

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_wait_for_device_no_valid_connections(mock_dev, mock_exit, mock_time, ub_obj):
    mock_dev.side_effect = NoValidConnectionsError({'error': 'test error value'})
    with pytest.raises(SystemExit):
        ub_obj.wait_for_device(2, 1)
    mock_exit.assert_called_with(
        results={'ok': False,
                 'error_type': 'login',
                 'message': 'Failed to connect to target %s within reload countdown' % ub_obj.cli_args.target}
    ) 
開發者ID:Apstra,項目名稱:aeon-ztps,代碼行數:11,代碼來源:test_centos_bootstrap.py

示例7: connect

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def connect(self):
        """connects to a remote instance"""
        instance = self.ec2.Instance(self.instance_id)
        try:
            self.ssh.connect(instance.public_dns_name, username='ec2-user',
                             key_filename=self.rsa_key, timeout=3.0)
        except NoValidConnectionsError:
            state = instance.state['Name']
            if state not in ['running', 'pending']:
                raise InstanceNotRunningError(
                    'instance %s in state %s. Only running instances can be connected to.'
                    % (self.instance_id, state))
            else:
                raise 
開發者ID:ambrosejcarr,項目名稱:seqc,代碼行數:16,代碼來源:ec2.py

示例8: test_pickling

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_pickling(self):
        # Regression test for https://github.com/paramiko/paramiko/issues/617
        exc = NoValidConnectionsError({('127.0.0.1', '22'): Exception()})
        new_exc = pickle.loads(pickle.dumps(exc))
        self.assertEqual(type(exc), type(new_exc))
        self.assertEqual(str(exc), str(new_exc))
        self.assertEqual(exc.args, new_exc.args) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:9,代碼來源:test_ssh_exception.py

示例9: test_error_message_for_single_host

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_error_message_for_single_host(self):
        exc = NoValidConnectionsError({('127.0.0.1', '22'): Exception()})
        assert "Unable to connect to port 22 on 127.0.0.1" in str(exc) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:5,代碼來源:test_ssh_exception.py

示例10: test_error_message_for_two_hosts

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_error_message_for_two_hosts(self):
        exc = NoValidConnectionsError({('127.0.0.1', '22'): Exception(),
                                       ('::1', '22'): Exception()})
        assert "Unable to connect to port 22 on 127.0.0.1 or ::1" in str(exc) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:6,代碼來源:test_ssh_exception.py

示例11: test_error_message_for_multiple_hosts

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def test_error_message_for_multiple_hosts(self):
        exc = NoValidConnectionsError({('127.0.0.1', '22'): Exception(),
                                       ('::1', '22'): Exception(),
                                       ('10.0.0.42', '22'): Exception()})
        exp = "Unable to connect to port 22 on 10.0.0.42, 127.0.0.1 or ::1"
        assert exp in str(exc) 
開發者ID:hpe-storage,項目名稱:python-hpedockerplugin,代碼行數:8,代碼來源:test_ssh_exception.py

示例12: exec_command_over_ssh

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def exec_command_over_ssh(self,
                              command: str = 'ifconfig',
                              ssh_user: str = 'root',
                              ssh_password: Union[None, str] = None,
                              ssh_pkey: Union[None, RSAKey] = None,
                              ssh_host: str = '192.168.0.1',
                              need_output: bool = True,
                              exit_on_failure: bool = True) -> Union[None, bool, str]:
        """
        Exec cmd command over SSH
        :param command: CMD command string (example: 'ifconfig')
        :param ssh_user: SSH user string (example: 'root')
        :param ssh_password: SSH password string or None if use ssh private key
        :param ssh_pkey: SSH private key or None if use ssh password
        :param ssh_host: SSH host string (example: '192.168.0.1')
        :param need_output: Need command output or not (default: True)
        :param exit_on_failure: Exit in case of error (default: False)
        :return: True or False if not need output, Output string or None if need output
        """
        command_result: Union[None, str] = None
        try:
            assert not (ssh_password is None and ssh_pkey is None), \
                'SSH password and private key is None'

            ssh_client: SSHClient = SSHClient()
            ssh_client.set_missing_host_key_policy(AutoAddPolicy())
            if ssh_password is not None:
                ssh_client.connect(hostname=ssh_host, username=ssh_user, password=ssh_password)
            if ssh_pkey is not None:
                ssh_client.connect(hostname=ssh_host, username=ssh_user, pkey=ssh_pkey)

            if need_output:
                stdin, stdout, stderr = ssh_client.exec_command(command)
                command_result = stdout.read().decode('utf-8') + stderr.read().decode('utf-8')
                ssh_client.close()
                return command_result
            else:
                ssh_client.exec_command(command)
                ssh_client.close()
                return True

        except AssertionError as Error:
            self.print_error(Error.args[0])

        except NoValidConnectionsError:
            self.print_error('Could not connect to SSH host: ', ssh_host)

        except AuthenticationException:
            self.print_error('SSH authentication error: ', ssh_user + '@' + ssh_host)

        except SSHException as Error:
            self.print_error('SSH Exception: ', Error.args[0])

        if exit_on_failure:
            exit(1)
        if need_output:
            return command_result
        else:
            return False 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:61,代碼來源:base.py

示例13: download_file_over_ssh

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def download_file_over_ssh(self,
                               remote_path: str = '/tmp/test.txt',
                               local_path: str = 'test.txt',
                               ssh_user: str = 'root',
                               ssh_password: Union[None, str] = None,
                               ssh_pkey: Union[None, RSAKey] = None,
                               ssh_host: str = '192.168.0.1',
                               exit_on_failure: bool = True) -> Union[bool]:
        """
        Transfer file over SSH
        :param remote_path: Remote file path string
        :param local_path: Local file path string
        :param ssh_user: SSH user string (example: 'root')
        :param ssh_password: SSH password string or None if use ssh private key
        :param ssh_pkey: SSH private key or None if use ssh password
        :param ssh_host: SSH host string (example: '192.168.0.1')
        :param exit_on_failure: Exit in case of error (default: False)
        :return: True or False if not need output, Output string or None if need output
        """
        try:
            assert not (ssh_password is None and ssh_pkey is None), \
                'SSH password and private key is None'

            ssh_client: SSHClient = SSHClient()
            ssh_client.set_missing_host_key_policy(AutoAddPolicy())
            if ssh_password is not None:
                ssh_client.connect(hostname=ssh_host, username=ssh_user, password=ssh_password)
            if ssh_pkey is not None:
                ssh_client.connect(hostname=ssh_host, username=ssh_user, pkey=ssh_pkey)

            sftp = ssh_client.open_sftp()
            sftp.get(remote_path, local_path)
            sftp.close()
            ssh_client.close()
            return True

        except AssertionError as Error:
            self.print_error(Error.args[0])

        except NoValidConnectionsError:
            self.print_error('Could not connect to SSH host: ', ssh_host)

        except AuthenticationException:
            self.print_error('SSH authentication error: ', ssh_user + '@' + ssh_host)

        except SSHException as Error:
            self.print_error('SSH Exception: ', Error.args[0])

        except FileNotFoundError:
            self.print_error('Not found remote file: ', remote_path)

        if exit_on_failure:
            exit(1)
        return False
    # endregion

# endregion 
開發者ID:raw-packet,項目名稱:raw-packet,代碼行數:59,代碼來源:base.py

示例14: wait_for_device

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def wait_for_device(self, countdown, poll_delay, msg=None):
        dev = None

        # first we need to wait for the device to be 'reachable' via the API.
        # we'll use the probe error to detect if it is or not

        while not dev:

            new_msg = msg or 'Waiting for device access via SSH. Timeout remaining: {} seconds'.format(countdown)
            self.post_device_status(message=new_msg, state='AWAIT-ONLINE')
            self.log.info(new_msg)

            try:
                dev = Device(self.target, user=self.user, passwd=self.passwd,
                             timeout=poll_delay)

            except AuthenticationException as e:
                self.log.info('Authentication exception reported: {} \n args: {}'.format(e, e.args))
                self.exit_results(results=dict(
                    ok=False,
                    error_type='login',
                    message='Unauthorized - check user/password'))

            except NoValidConnectionsError as e:
                countdown -= poll_delay
                if countdown <= 0:
                    self.exit_results(results=dict(
                        ok=False,
                        error_type='login',
                        message='Failed to connect to target %s within reload countdown' % self.target))

            except LoginNotReadyError as e:
                countdown -= poll_delay
                if countdown <= 0:
                    self.exit_results(results=dict(
                        ok=False,
                        error_type='login',
                        message='Failed to connect to target %s within reload countdown' % self.target))

                time.sleep(poll_delay)

        self.dev = dev
        self.post_device_facts() 
開發者ID:Apstra,項目名稱:aeon-ztps,代碼行數:45,代碼來源:opx_bootstrap.py

示例15: wait_for_device

# 需要導入模塊: from paramiko import ssh_exception [as 別名]
# 或者: from paramiko.ssh_exception import NoValidConnectionsError [as 別名]
def wait_for_device(self, countdown, poll_delay, msg=None):
        dev = None

        # first we need to wait for the device to be 'reachable' via the API.
        # we'll use the probe error to detect if it is or not

        while not dev:
            new_msg = msg or 'OS installation in progress. Timeout remaining: {} seconds'.format(countdown)
            self.post_device_status(message=new_msg, state='AWAIT-ONLINE')
            self.log.info(new_msg)

            try:
                dev = Device(self.target, user=self.user, passwd=self.passwd,
                             timeout=poll_delay)

            except AuthenticationException as e:
                self.log.info('Authentication exception reported: {} \n args: {}'.format(e, e.args))
                self.exit_results(results=dict(
                    ok=False,
                    error_type='login',
                    message='Unauthorized - check user/password'))

            except NoValidConnectionsError as e:
                countdown -= poll_delay
                if countdown <= 0:
                    self.exit_results(results=dict(
                        ok=False,
                        error_type='login',
                        message='Failed to connect to target %s within reload countdown' % self.target))

            except LoginNotReadyError as e:
                countdown -= poll_delay
                if countdown <= 0:
                    self.exit_results(results=dict(
                        ok=False,
                        error_type='login',
                        message='Failed to connect to target %s within reload countdown' % self.target))

                time.sleep(poll_delay)

        self.dev = dev
        self.post_device_facts() 
開發者ID:Apstra,項目名稱:aeon-ztps,代碼行數:44,代碼來源:cumulus_bootstrap.py


注:本文中的paramiko.ssh_exception.NoValidConnectionsError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。