Celluloid with Net::SSH in 2018?

42 views
Skip to first unread message

Aaron D. Gifford

unread,
Aug 23, 2018, 9:51:11 AM8/23/18
to Celluloid
For perhaps a year or two, whenever consider updating some single-threaded scripts I use that use Net::SSH to talk to some devices, I do a search for various async Ruby ways to modify things and parallelize the aforementioned scripts.  In the past I've resorted to simply forking a bunch of processes, but I'd like to avoid that if possible.  Every search, however, returns the same 2015 results where some folks mention that Celluloid::IO is compatible with Net::SSH, but those results do not include any useful examples, and are full of caveats and warnings about some proxy parameter (never actually demonstrated in use) not being supported.

So, in 2018, what is the state of Net::SSH compatibility with Celluloid?

Say I was trying something a little like:

class Foo
  include Celluloid
  ...
  def do_connect
    @ssh = Net::SSH.start(...)
  end

  def do_some_command(cmd)
    @blah << @ssh.exec!(cmd)
  end
  ...
end

... code that creates several instances of Foo with various SSH IP/user/host configurations ...

...
foo_instance_5.async.do_connect
foo_instance_6.async.do_connect
...
foo_instance_1.async.do_command(...)
foo_instance_9.async.do_command(...)
...

And so on.  Anyone up for providing some examples how I can encourage SSH to NOT BLOCK using Celluloid?  Or is it a no-win situation where Net::SSH just isn't going to cooperate, even in 2018?

Thanks for any/all pointers!

Aaron out.

Tiago Cardoso

unread,
Aug 27, 2018, 7:16:24 PM8/27/18
to Celluloid
net-ssh certainly doesn't support celluloid-io out of the box and vice-versa. That's because net-ssh manages its own io loop, while celluloid-io wants you to use its network socket duck types. And let's not forget the whole filesystem key verification operations which just break any IO loop...

You can get away with it using monkey-patching and being frugal in the ssh features you'll want support to. I've used [these patches](https://gist.github.com/HoneyryderChuck/ceaa809ff2bc9a461484) to build support for a previous company I worked for. You'll still need to use the proxy argument, you best unselect the strategy that inserts a new host key into the known_hosts file, and you best not be using jruby. Other than that, it worked very well for them, considering how ugly that patch is. 
Reply all
Reply to author
Forward
0 new messages