9
9
10
10
11
11
class Nodes (object ):
12
- def __init__ (self , nodes , dry_run = False , ssh_user = None , queue_size = 0 ):
12
+ def __init__ (self , nodes , dry_run = False , ssh_user = None , queue_size = 0 , ssh_key_path = None ):
13
13
assert isinstance (nodes , list )
14
14
assert len (nodes ) > 0
15
15
assert isinstance (nodes [0 ], str )
16
16
self ._nodes = nodes
17
17
self ._dry_run = bool (dry_run )
18
18
self ._ssh_user = ssh_user
19
+ self ._ssh_key_path = ssh_key_path
19
20
self ._logger = logger .getChild (self .__class__ .__name__ )
20
21
self ._queue = queue .Queue (queue_size )
21
22
self ._qsize = queue_size
@@ -24,12 +25,15 @@ def __init__(self, nodes, dry_run=False, ssh_user=None, queue_size=0):
24
25
def nodes_list (self ):
25
26
return self ._nodes
26
27
27
- def _get_ssh_command_prefix (self ):
28
+ def _get_ssh_command_prefix (self , remote = False ):
28
29
command = []
29
30
command .extend (['ssh' , '-o' , 'StrictHostKeyChecking=no' , '-o' , 'UserKnownHostsFile=/dev/null' , '-A' ])
30
31
if (self ._ssh_user ):
31
32
command .extend (['-l' , self ._ssh_user ])
32
33
34
+ if not remote and self ._ssh_key_path :
35
+ command .extend (['-i' , self ._ssh_key_path ])
36
+
33
37
return command
34
38
35
39
def _check_async_execution (self , running_jobs , check_retcode = True , results = None ):
@@ -144,9 +148,9 @@ def _copy_between_nodes(self, hub, hub_path, hosts, remote_path):
144
148
if self ._dry_run :
145
149
continue
146
150
cmd = self ._get_ssh_command_prefix () + [dst ]
147
- rsh = " " .join (self ._get_ssh_command_prefix ())
151
+ rsh = " " .join (self ._get_ssh_command_prefix (remote = True ))
148
152
cmd .extend ([
149
- "sudo" , "SSH_AUTH_SOCK=$ SSH_AUTH_SOCK" , "rsync" , "-avqW" , "--del" , "--no-o" , "--no-g" ,
153
+ "sudo" , "--preserve-env= SSH_AUTH_SOCK" , "rsync" , "-avqW" , "--del" , "--no-o" , "--no-g" ,
150
154
"--rsh='{}'" .format (rsh ),
151
155
src , remote_path
152
156
])
0 commit comments