本文整理汇总了Python中pssh.ParallelSSHClient.hosts方法的典型用法代码示例。如果您正苦于以下问题:Python ParallelSSHClient.hosts方法的具体用法?Python ParallelSSHClient.hosts怎么用?Python ParallelSSHClient.hosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pssh.ParallelSSHClient
的用法示例。
在下文中一共展示了ParallelSSHClient.hosts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_per_host_dict_args
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import hosts [as 别名]
def test_per_host_dict_args(self):
server2_socket = make_socket('127.0.0.2', port=self.listen_port)
server2_port = server2_socket.getsockname()[1]
server2 = start_server(server2_socket)
server3_socket = make_socket('127.0.0.3', port=self.listen_port)
server3_port = server3_socket.getsockname()[1]
server3 = start_server(server3_socket)
hosts = [self.host, '127.0.0.2', '127.0.0.3']
hosts_gen = (h for h in hosts)
host_args = [dict(zip(('host_arg1', 'host_arg2',),
('arg1-%s' % (i,), 'arg2-%s' % (i,),)))
for i, _ in enumerate(hosts)]
cmd = 'echo %(host_arg1)s %(host_arg2)s'
client = ParallelSSHClient(hosts, port=self.listen_port,
pkey=self.user_key)
output = client.run_command(cmd, host_args=host_args)
for i, host in enumerate(hosts):
expected = ["%(host_arg1)s %(host_arg2)s" % host_args[i]]
stdout = list(output[host]['stdout'])
self.assertEqual(expected, stdout)
self.assertTrue(output[host]['exit_code'] == 0)
self.assertRaises(HostArgumentException, client.run_command,
cmd, host_args=[host_args[0]])
# Host list generator should work also
client.hosts = hosts_gen
output = client.run_command(cmd, host_args=host_args)
for i, host in enumerate(hosts):
expected = ["%(host_arg1)s %(host_arg2)s" % host_args[i]]
stdout = list(output[host]['stdout'])
self.assertEqual(expected, stdout)
self.assertTrue(output[host]['exit_code'] == 0)
client.hosts = (h for h in hosts)
self.assertRaises(HostArgumentException, client.run_command,
cmd, host_args=[host_args[0]])
示例2: test_pssh_hosts_iterator_hosts_modification
# 需要导入模块: from pssh import ParallelSSHClient [as 别名]
# 或者: from pssh.ParallelSSHClient import hosts [as 别名]
def test_pssh_hosts_iterator_hosts_modification(self):
"""Test using iterator as host list and modifying host list in place"""
server2_socket = make_socket("127.0.0.2", port=self.listen_port)
server2_port = server2_socket.getsockname()[1]
server2 = start_server(server2_socket)
server3_socket = make_socket("127.0.0.3", port=self.listen_port)
server3_port = server3_socket.getsockname()[1]
server3 = start_server(server3_socket)
hosts = [self.host, "127.0.0.2"]
client = ParallelSSHClient(iter(hosts), port=self.listen_port, pkey=self.user_key, pool_size=1)
output = client.run_command(self.fake_cmd)
stdout = [list(output[k]["stdout"]) for k in output]
expected_stdout = [[self.fake_resp], [self.fake_resp]]
self.assertEqual(
len(hosts),
len(output),
msg="Did not get output from all hosts. Got output for " "%s/%s hosts" % (len(output), len(hosts)),
)
# Run again without re-assigning host list, should do nothing
output = client.run_command(self.fake_cmd)
self.assertFalse(hosts[0] in output, msg="Expected no host output, got %s" % (output,))
self.assertFalse(output, msg="Expected empty output, got %s" % (output,))
# Re-assigning host list with new hosts should work
hosts = ["127.0.0.2", "127.0.0.3"]
client.hosts = iter(hosts)
output = client.run_command(self.fake_cmd)
self.assertEqual(
len(hosts),
len(output),
msg="Did not get output from all hosts. Got output for " "%s/%s hosts" % (len(output), len(hosts)),
)
self.assertTrue(hosts[1] in output, msg="Did not get output for new host %s" % (hosts[1],))
del client, server2, server3