Sha256: f07ebe11900cfc6198bc255ce5836b9f7cceb897dce87eb3104a2b5d0f759530

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

require 'parallel'

module Koma
  module Backend
    class Ssh < Base
      attr_reader :host, :options

      def gather
        if host.include?(',')
          list = host.split(',')
          results = Parallel.map(list, in_thread: 4) do |h|
            gather_via_ssh(h, options)
          end
          arr = [list, results].transpose
          result = Hash[*arr.flatten]
        else
          result = gather_via_ssh(host, options)
        end
        result
      end

      def gather_via_ssh(host, options)
        user, host = host.split('@') if host.include?('@')
        set :backend, :ssh
        set :host, host
        set :request_pty, true
        ssh_options = Net::SSH::Config.for(host)
        ssh_options[:user] = user if user
        ssh_options[:keys] = [options[:identity_file]] if options[:identity_file]
        ssh_options[:port] = options[:port] if options[:port]
        set :ssh_options, ssh_options
        out(options[:key])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
koma-0.6.0 lib/koma/backend/ssh.rb
koma-0.5.0 lib/koma/backend/ssh.rb