当前位置: 首页>>代码示例>>Python>>正文


Python ParamikoSSHClient.connect方法代码示例

本文整理汇总了Python中st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Python ParamikoSSHClient.connect方法的具体用法?Python ParamikoSSHClient.connect怎么用?Python ParamikoSSHClient.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient的用法示例。


在下文中一共展示了ParamikoSSHClient.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_with_key_via_bastion

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_with_key_via_bastion(self):
        conn_params = {
            "hostname": "dummy.host.org",
            "bastion_host": "bastion.host.org",
            "username": "ubuntu",
            "key_files": "id_rsa",
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_bastion_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "bastion.host.org",
            "look_for_keys": False,
            "key_filename": "id_rsa",
            "timeout": 60,
            "port": 22,
        }
        mock.bastion_client.connect.assert_called_once_with(**expected_bastion_conn)

        expected_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "key_filename": "id_rsa",
            "timeout": 60,
            "port": 22,
            "sock": mock.bastion_socket,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:34,代码来源:test_paramiko_ssh.py

示例2: test_create_with_key_via_bastion

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_with_key_via_bastion(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'bastion_host': 'bastion.host.org',
                       'username': 'ubuntu',
                       'key_files': 'id_rsa'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_bastion_conn = {'username': 'ubuntu',
                                 'allow_agent': False,
                                 'hostname': 'bastion.host.org',
                                 'look_for_keys': False,
                                 'key_filename': 'id_rsa',
                                 'timeout': 60,
                                 'port': 22}
        mock.bastion_client.connect.assert_called_once_with(**expected_bastion_conn)

        expected_conn = {'username': 'ubuntu',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'key_filename': 'id_rsa',
                         'timeout': 60,
                         'port': 22,
                         'sock': mock.bastion_socket}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:28,代码来源:test_paramiko_ssh.py

示例3: run

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def run(self, hostname, port, username, password=None, keyfile=None, ssh_timeout=5,
            sleep_delay=20, retries=10):
        # Note: If neither password nor key file is provided, we try to use system user
        # key file
        if not password and not keyfile:
            keyfile = cfg.CONF.system_user.ssh_key_file
            self.logger.info('Neither "password" nor "keyfile" parameter provided, '
                             'defaulting to using "%s" key file' % (keyfile))

        client = ParamikoSSHClient(hostname=hostname, port=port, username=username,
                                   password=password, key_files=keyfile,
                                   timeout=ssh_timeout)

        for index in range(retries):
            attempt = index + 1

            try:
                self.logger.debug('SSH connection attempt: %s' % (attempt))
                client.connect()
                return True
            except Exception as e:
                self.logger.info('Attempt %s failed (%s), sleeping for %s seconds...' %
                                 (attempt, str(e), sleep_delay))
                time.sleep(sleep_delay)

        raise Exception('Exceeded max retries (%s)' % (retries))
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:28,代码来源:wait_for_ssh.py

示例4: _connect

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def _connect(self, host, results, raise_on_any_error=False):
        (hostname, port) = self._get_host_port_info(host)

        extra = {'host': host, 'port': port, 'user': self._ssh_user}
        if self._ssh_password:
            extra['password'] = '<redacted>'
        elif self._ssh_key_file:
            extra['key_file_path'] = self._ssh_key_file
        else:
            extra['private_key'] = '<redacted>'

        LOG.debug('Connecting to host.', extra=extra)

        client = ParamikoSSHClient(hostname, username=self._ssh_user,
                                   password=self._ssh_password,
                                   key=self._ssh_key_file,
                                   key_material=self._ssh_key_material,
                                   port=port)
        try:
            client.connect()
        except:
            error = 'Failed connecting to host %s.' % hostname
            LOG.exception(error)
            _, ex, tb = sys.exc_info()
            if raise_on_any_error:
                raise
            error = ' '.join([self.CONNECT_ERROR, str(ex)])
            error_dict = self._generate_error_result(error, tb)
            self._bad_hosts[hostname] = error_dict
            results[hostname] = error_dict
        else:
            self._successful_connects += 1
            self._hosts_client[hostname] = client
            results[hostname] = {'message': 'Connected to host.'}
开发者ID:jspittman,项目名称:st2,代码行数:36,代码来源:parallel_ssh.py

示例5: test_create_with_password

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_with_password(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu',
                       'password': 'ubuntu'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': 'ubuntu',
                         'password': 'ubuntu',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:joshgre,项目名称:st2,代码行数:16,代码来源:test_paramiko_ssh.py

示例6: test_deprecated_key_argument

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_deprecated_key_argument(self):
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu',
                       'key': 'id_rsa'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': 'ubuntu',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'key_filename': 'id_rsa',
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:joshgre,项目名称:st2,代码行数:16,代码来源:test_paramiko_ssh.py

示例7: test_key_with_passphrase_success

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_key_with_passphrase_success(self):
        path = os.path.join(get_resources_base_path(), "ssh", "dummy_rsa_passphrase")

        with open(path, "r") as fp:
            private_key = fp.read()

        # Key material provided
        conn_params = {
            "hostname": "dummy.host.org",
            "username": "ubuntu",
            "key_material": private_key,
            "passphrase": "testphrase",
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key), "testphrase")
        expected_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "pkey": pkey,
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)

        # Path to private key file provided
        conn_params = {
            "hostname": "dummy.host.org",
            "username": "ubuntu",
            "key_files": path,
            "passphrase": "testphrase",
        }
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "key_filename": path,
            "password": "testphrase",
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:51,代码来源:test_paramiko_ssh.py

示例8: test_deprecated_key_argument

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_deprecated_key_argument(self):
        conn_params = {"hostname": "dummy.host.org", "username": "ubuntu", "key_files": "id_rsa"}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "key_filename": "id_rsa",
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:17,代码来源:test_paramiko_ssh.py

示例9: test_create_with_password

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_with_password(self):
        conn_params = {"hostname": "dummy.host.org", "username": "ubuntu", "password": "ubuntu"}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "ubuntu",
            "password": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:17,代码来源:test_paramiko_ssh.py

示例10: test_create_without_credentials_use_default_key

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_without_credentials_use_default_key(self):
        # No credentials are provided by default stanley ssh key exists so it should use that
        cfg.CONF.set_override(name='ssh_key_file', override='stanley_rsa', group='system_user')

        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': 'ubuntu',
                         'hostname': 'dummy.host.org',
                         'key_filename': 'stanley_rsa',
                         'allow_agent': False,
                         'look_for_keys': False,
                         'timeout': 60,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:yangjiebeijing,项目名称:st2,代码行数:19,代码来源:test_paramiko_ssh.py

示例11: test_create_without_credentials_use_default_key

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_without_credentials_use_default_key(self):
        # No credentials are provided by default stanley ssh key exists so it should use that
        cfg.CONF.set_override(name="ssh_key_file", override="stanley_rsa", group="system_user")

        conn_params = {"hostname": "dummy.host.org", "username": "ubuntu"}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "ubuntu",
            "hostname": "dummy.host.org",
            "key_filename": "stanley_rsa",
            "allow_agent": False,
            "look_for_keys": False,
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:20,代码来源:test_paramiko_ssh.py

示例12: test_create_without_credentials

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_without_credentials(self):
        """
        Initialize object with no credentials.

        Just to have better coverage, initialize the object
        without 'password' neither 'key'.
        """
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': 'ubuntu',
                         'hostname': 'dummy.host.org',
                         'allow_agent': True,
                         'look_for_keys': True,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:joshgre,项目名称:st2,代码行数:20,代码来源:test_paramiko_ssh.py

示例13: test_key_with_passphrase_success

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_key_with_passphrase_success(self):
        path = os.path.join(get_resources_base_path(),
                            'ssh', 'dummy_rsa_passphrase')

        with open(path, 'r') as fp:
            private_key = fp.read()

        # Key material provided
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu',
                       'key_material': private_key,
                       'passphrase': 'testphrase'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key), 'testphrase')
        expected_conn = {'username': 'ubuntu',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'pkey': pkey,
                         'timeout': 60,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)

        # Path to private key file provided
        conn_params = {'hostname': 'dummy.host.org',
                       'username': 'ubuntu',
                       'key_files': path,
                       'passphrase': 'testphrase'}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {'username': 'ubuntu',
                         'allow_agent': False,
                         'hostname': 'dummy.host.org',
                         'look_for_keys': False,
                         'key_filename': path,
                         'password': 'testphrase',
                         'timeout': 60,
                         'port': 22}
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:yangjiebeijing,项目名称:st2,代码行数:44,代码来源:test_paramiko_ssh.py

示例14: test_create_without_credentials

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_create_without_credentials(self):
        """
        Initialize object with no credentials.

        Just to have better coverage, initialize the object
        without 'password' neither 'key'.
        """
        conn_params = {"hostname": "dummy.host.org", "username": "ubuntu"}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        expected_conn = {
            "username": "ubuntu",
            "hostname": "dummy.host.org",
            "allow_agent": True,
            "look_for_keys": True,
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:22,代码来源:test_paramiko_ssh.py

示例15: test_key_material_argument

# 需要导入模块: from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient [as 别名]
# 或者: from st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient import connect [as 别名]
    def test_key_material_argument(self):
        path = os.path.join(get_resources_base_path(), "ssh", "dummy_rsa")

        with open(path, "r") as fp:
            private_key = fp.read()

        conn_params = {"hostname": "dummy.host.org", "username": "ubuntu", "key_material": private_key}
        mock = ParamikoSSHClient(**conn_params)
        mock.connect()

        pkey = paramiko.RSAKey.from_private_key(StringIO(private_key))
        expected_conn = {
            "username": "ubuntu",
            "allow_agent": False,
            "hostname": "dummy.host.org",
            "look_for_keys": False,
            "pkey": pkey,
            "timeout": 60,
            "port": 22,
        }
        mock.client.connect.assert_called_once_with(**expected_conn)
开发者ID:rlugojr,项目名称:st2,代码行数:23,代码来源:test_paramiko_ssh.py


注:本文中的st2actions.runners.ssh.paramiko_ssh.ParamikoSSHClient.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。