Class: Fog::SSH
- Inherits:
-
Object
- Object
- Fog::SSH
- Defined in:
- lib/fog/ssh.rb
Instance Method Summary collapse
-
#initialize(address, username, options = {}) ⇒ SSH
constructor
A new instance of SSH.
- #run(commands) ⇒ Object
Constructor Details
#initialize(address, username, options = {}) ⇒ SSH
Returns a new instance of SSH.
5 6 7 8 9 10 11 12 |
# File 'lib/fog/ssh.rb', line 5 def initialize(address, username, = {}) unless [:keys] || [:password] raise ArgumentError.new(':keys or :password are required to initialize SSH') end @address = address @username = username @options = .merge!(:paranoid => false) end |
Instance Method Details
#run(commands) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/ssh.rb', line 14 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 |