Class: Conjure::Service::RemoteShell
- Inherits:
-
Object
- Object
- Conjure::Service::RemoteShell
- Defined in:
- lib/conjure/service/remote_shell.rb
Defined Under Namespace
Classes: Result
Class Attribute Summary collapse
-
.ssh_service ⇒ Object
Returns the value of attribute ssh_service.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RemoteShell
constructor
A new instance of RemoteShell.
- #poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
- #run(command, options = {}, &block) ⇒ Object
- #session ⇒ Object
- #with_raw_tty ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RemoteShell
Returns a new instance of RemoteShell.
11 12 13 |
# File 'lib/conjure/service/remote_shell.rb', line 11 def initialize( = {}) @options = end |
Class Attribute Details
.ssh_service ⇒ Object
Returns the value of attribute ssh_service.
7 8 9 |
# File 'lib/conjure/service/remote_shell.rb', line 7 def ssh_service @ssh_service end |
Instance Method Details
#poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
47 48 49 |
# File 'lib/conjure/service/remote_shell.rb', line 47 def poll_stream(stream, &block) yield stream.sysread(1) if IO.select([stream], nil, nil, 0.01) end |
#run(command, options = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/conjure/service/remote_shell.rb', line 15 def run(command, = {}, &block) Log.debug " [ssh] #{command}" result = nil session.open_channel do |channel| channel.request_pty channel.exec command do |c, success| raise "Failed to execute command via SSH" unless success result = Result.new(channel, &block) end if [:stream_stdin] channel.on_process do poll_stream(STDIN) { |data| channel.send_data data } end end end if [:stream_stdin] with_raw_tty { session.loop 0.01 } else session.loop end result end |
#session ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/conjure/service/remote_shell.rb', line 38 def session = { :auth_methods => ["publickey"], :paranoid => false, :forward_agent => true, } @session ||= self.class.ssh_service.start @options[:ip_address], @options[:username], end |
#with_raw_tty ⇒ Object
51 52 53 54 55 56 |
# File 'lib/conjure/service/remote_shell.rb', line 51 def with_raw_tty system "stty raw -echo" yield ensure system "stty -raw echo" end |