Class: Evrone::Common::Spawn::SSH
- Inherits:
-
Object
- Object
- Evrone::Common::Spawn::SSH
- Defined in:
- lib/evrone/common/spawn/ssh.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ssh) ⇒ SSH
constructor
A new instance of SSH.
- #spawn(*args, &block) ⇒ Object
Constructor Details
#initialize(ssh) ⇒ SSH
Returns a new instance of SSH.
21 22 23 |
# File 'lib/evrone/common/spawn/ssh.rb', line 21 def initialize(ssh) @connection = ssh end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
19 20 21 |
# File 'lib/evrone/common/spawn/ssh.rb', line 19 def connection @connection end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
19 20 21 |
# File 'lib/evrone/common/spawn/ssh.rb', line 19 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/evrone/common/spawn/ssh.rb', line 19 def @options end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'lib/evrone/common/spawn/ssh.rb', line 19 def user @user end |
Class Method Details
.open(host, user, options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/evrone/common/spawn/ssh.rb', line 10 def open(host, user, = {}, &block) ::Net::SSH.start(host, user, { paranoid: false }.merge()) do |ssh| yield new(ssh) end end |
Instance Method Details
#spawn(*args, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/evrone/common/spawn/ssh.rb', line 25 def spawn(*args, &block) env = args.first.is_a?(Hash) ? args.shift : {} = args.last.is_a?(Hash) ? args.pop : {} command = args.join(" ") exit_code = nil timeout = Spawn::Timeout.new .delete(:timeout) read_timeout = Spawn::ReadTimeout.new .delete(:read_timeout) command = build_command(env, command, ) channel = spawn_channel command, read_timeout, &block channel.on_request("exit-status") do |_,data| exit_code = data.read_long end pool channel, timeout, read_timeout compute_exit_code command, exit_code, timeout, read_timeout end |