Welcome, guest | Sign In | My Account | Store | Cart

execnet ( http://codespeak.net/execnet/ ) is pretty cool, but its ssh support needs a few tweaks, here they are.

This snipped is a monkey patch, not a diff, import it and you can use execnet.makeportgateway instead of makegateway.

Adapt to your needs even more!

Python, 34 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
import execnet, execnet.gateway, execnet.multi
class SshPortGateway(execnet.gateway.SshGateway):
  def __init__(self, sshaddress, id, remotepython = None,
               ssh_config=None,
               ssh_port=None,
               ssh_identity=None,
               ssh_batchmode=None):
    self.remoteaddress = sshaddress
    if not remotepython: remotepython = "python"
    args = ['ssh', '-C' ]
    if ssh_config: args.extend(['-F', ssh_config])
    if ssh_port: args.extend(['-p', ssh_port])
    if ssh_identity: args.extend(['-i', ssh_identity])
    if ssh_batchmode: args.extend(["-o", "BatchMode yes"])
    remotecmd = '%s -c "%s"' % (remotepython, execnet.gateway.popen_bootstrapline)
    args.extend([sshaddress, remotecmd])
    execnet.gateway.PopenCmdGateway.__init__(self, args, id=id)
def makeportgateway(self, spec):
  spec = execnet.XSpec(spec)
  self.allocate_id(spec)
  gw = SshPortGateway(spec.ssh,
                      remotepython=spec.python,
                      ssh_config=spec.ssh_config,
                      id=spec.id,
                      ssh_port=spec.ssh_port,
                      ssh_identity=spec.ssh_identity,
                      ssh_batchmode=spec.ssh_batchmode)
  gw.spec = spec
  self._register(gw)
  # TODO add spec.{chdir,nice,env}
  return gw
execnet.multi.Group.makeportgateway = makeportgateway
execnet.makeportgateway = execnet.multi.default_group.makeportgateway

3 comments

Ronny Pfannschmidt 11 years, 11 months ago  # | flag

we would have appreciated a note to add that to execnet itself

Dima Tisnek (author) 11 years, 11 months ago  # | flag

I thought I tried to send an email to the list, but now I can't find it, I guess I just forgot!

Ronny Pfannschmidt 11 years, 10 months ago  # | flag

another note / as of now, that code wont work with the develop version of execnet, sshgateway is gone