Python 结构组-主机到字符串的列表

Python 结构组-主机到字符串的列表,python,python-3.x,fabric,Python,Python 3.x,Fabric,使用Fabric2,您可以创建一个组,以串行或线程方式执行命令 g = ThreadingGroup('192.168.101.5', '192.168.101.10', user='username', port=22, connect_kwargs={'password': 'password'}) g.run('uptime') # Returns: # {<Connection host=192.168.101.10 user=esp>: <Result cm

使用Fabric2,您可以创建一个组,以串行或线程方式执行命令

g = ThreadingGroup('192.168.101.5', '192.168.101.10', user='username', port=22, connect_kwargs={'password': 'password'})    
g.run('uptime')

# Returns:
# {<Connection host=192.168.101.10 user=esp>: <Result cmd='uptime' exited=0>, <Connection host=192.168.101.5 user=esp>: <Result cmd='uptime' exited=0>}
g=ThreadingGroup('192.168.101.5','192.168.101.10',user='username',port=22,connect_-kwargs={'password':'password'})
g、 运行(‘正常运行时间’)
#返回:
# {: , : }
如果我传入一个列表,我会收到一个rsplit错误,因为需要一组字符串。然后,我将列表转换为字符串,然后再次运行:

s = str(servers).strip('[]')
g = ThreadingGroup(s, user='username', port=22, connect_kwargs={'password': 'password'})
g.run('uptime')

# fabric.exceptions.GroupException: {<Connection host='192.168.101.5', '192.168.101.10' user=username>: gaierror(-2, 'Name or service not known')}
s=str(服务器).strip(“[]”)
g=线程组(s,user='username',port=22,connect_-kwargs={'password':'password'})
g、 运行(‘正常运行时间’)
#fabric.exceptions.GroupException:{:gaierror(-2,'名称或服务未知')}

在后一个示例中,“连接主机”正在合并,而不是像前一个示例中那样分离。如何协调这一点?

您不能将列表作为第一个参数传递,这将不起作用。您需要解压缩列表:

g = ThreadingGroup(*s, user='username', port=22, connect_kwargs={'password': 'password'})