Class: SmartCloud::SSH
Instance Method Summary collapse
-
#initialize ⇒ SSH
constructor
A new instance of SSH.
- #login ⇒ Object
- #run(*commands) ⇒ Object
Methods included from Logger
configure_logger_for, included, #logger, logger_for
Constructor Details
#initialize ⇒ SSH
Returns a new instance of SSH.
6 7 |
# File 'lib/smart_cloud/ssh.rb', line 6 def initialize end |
Instance Method Details
#login ⇒ Object
39 40 41 |
# File 'lib/smart_cloud/ssh.rb', line 39 def login exec "ssh #{SmartCloud.credentials.machine[:username]}@#{SmartCloud.credentials.machine[:address]}" end |
#run(*commands) ⇒ Object
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 35 36 37 |
# File 'lib/smart_cloud/ssh.rb', line 9 def run(*commands) commands.flatten! Net::SSH.start(SmartCloud.credentials.machine[:address], SmartCloud.credentials.machine[:username], { port: SmartCloud.credentials.machine[:port], password: SmartCloud.credentials.machine[:password] }) do |ssh| channel = ssh.open_channel do |channel, success| channel.request_pty do |channel, success| channel.exec commands.join(';') do |channel, success| raise "Could not execute command" unless success channel.on_data do |channel, data| $stdout.print data if data =~ /^\[sudo\] password for / channel.send_data "#{SmartCloud.credentials.machine[:password]}\n" end end channel.on_extended_data do |channel, type, data| $stderr.print data end channel.on_close do |channel| # puts "done!" end end end end channel.wait end end |