当前位置: 首页>>代码示例>>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;未经允许,请勿转载。