Class: Conjure::Service::RemoteShell
- Inherits:
-
Object
- Object
- Conjure::Service::RemoteShell
- Defined in:
- lib/conjure/service/remote_shell.rb
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.
- #key_data ⇒ Object
- #poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
- #run(command, options = {}) ⇒ Object
- #session ⇒ Object
- #with_raw_tty ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ RemoteShell
11 12 13 |
# File 'lib/conjure/service/remote_shell.rb', line 11 def initialize( = {}) = 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
#key_data ⇒ Object
52 53 54 |
# File 'lib/conjure/service/remote_shell.rb', line 52 def key_data File.read [:private_key_path] if [:private_key_path] end |
#poll_stream(stream) {|stream.sysread(1)| ... } ⇒ Object
56 57 58 |
# File 'lib/conjure/service/remote_shell.rb', line 56 def poll_stream(stream, &block) yield stream.sysread(1) if IO.select([stream], nil, nil, 0.01) end |
#run(command, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/conjure/service/remote_shell.rb', line 15 def run(command, = {}) stdout, stderr, exit_status = ["", "", nil] session.open_channel do |channel| channel.request_pty channel.exec command do |c, success| raise "Failed to execute command via SSH" unless success channel.on_data do |c, data| yield data if block_given? stdout << data end channel.on_extended_data { |c, type, data| stderr << data } channel.on_request("exit-status") { |c, data| exit_status = data.read_long } 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.new stdout, stderr, exit_status end |
#session ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/conjure/service/remote_shell.rb', line 42 def session = { :auth_methods => ["publickey"], :key_data => key_data, :keys_only => true, :paranoid => false, } @session ||= self.class.ssh_service.start [:ip_address], [:username], end |
#with_raw_tty ⇒ Object
60 61 62 63 64 65 |
# File 'lib/conjure/service/remote_shell.rb', line 60 def with_raw_tty system "stty raw -echo" yield ensure system "stty -raw echo" end |