Sha256: 4a7730ffeb3c381c91b826984b376616d53a548f16772f586ad505ff871a11bc

Contents?: true

Size: 1.14 KB

Versions: 11

Compression:

Stored size: 1.14 KB

Contents

module Fog

  class SSH

    def initialize(address, username, options = {})
      unless options[:keys] || options[:password]
        raise ArgumentError.new(':keys or :password are required to initialize SSH')
      end
      @address  = address
      @username = username
      @options  = options.merge!(:paranoid => false)
    end

    def run(commands)
      commands = [*commands]
      results = []
      Net::SSH.start(@address, @username, @options) do |ssh|
        commands.each do |command|
          ssh.open_channel do |channel|
            channel.request_pty
            result = { :command => command }
            channel.exec(command.sub(/^sudo/, %q{sudo -p 'fog sudo password:'})) do |channel, success|
              channel.on_data do |channel, data|
                if data.strip == 'fog sudo password:'
                  channel.send_data("#{@options[:password]}\n")
                else
                  result[:data] ||= ''
                  result[:data] << data
                end
              end
            end
            results << result
          end
          ssh.loop
        end
      end
      results
    end

  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fog-0.0.84 lib/fog/ssh.rb
fog-0.0.83 lib/fog/ssh.rb
fog-0.0.82 lib/fog/ssh.rb
fog-0.0.81 lib/fog/ssh.rb
fog-0.0.80 lib/fog/ssh.rb
fog-0.0.79 lib/fog/ssh.rb
fog-0.0.78 lib/fog/ssh.rb
fog-0.0.77 lib/fog/ssh.rb
fog-0.0.76 lib/fog/ssh.rb
fog-0.0.75 lib/fog/ssh.rb
fog-0.0.74 lib/fog/ssh.rb