Class: HereOrThere::Remote::SSH
- Inherits:
-
Object
- Object
- HereOrThere::Remote::SSH
- Defined in:
- lib/here_or_there/remote.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #close_session ⇒ Object
-
#initialize(options) ⇒ SSH
constructor
A new instance of SSH.
- #run(command) ⇒ Object
Constructor Details
#initialize(options) ⇒ SSH
Returns a new instance of SSH.
25 26 27 28 29 |
# File 'lib/here_or_there/remote.rb', line 25 def initialize @options = .dup @hostname = @options.delete(:hostname) @user = @options.delete(:user) end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
22 23 24 |
# File 'lib/here_or_there/remote.rb', line 22 def hostname @hostname end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/here_or_there/remote.rb', line 22 def @options end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
23 24 25 |
# File 'lib/here_or_there/remote.rb', line 23 def session @session end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
22 23 24 |
# File 'lib/here_or_there/remote.rb', line 22 def user @user end |
Instance Method Details
#close_session ⇒ Object
54 55 56 |
# File 'lib/here_or_there/remote.rb', line 54 def close_session session.close unless !session || session.closed? end |
#run(command) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/here_or_there/remote.rb', line 31 def run command stdout, stderr, status = [ '', '', true ] open_session session.exec! command do |channel, response_type, response_data| if response_type == :stdout stdout << response_data else stderr << response_data status = false end end return Response.new( stdout, stderr, status ) rescue Net::SSH::AuthenticationFailed close_session return Response.new( '', 'Authentication failed when connecting to remote', false ) end |