Class: RemoteExec::Ssh
Overview
Class to help establish SSH connections, issue remote commands, and transfer files between a local system and remote node.
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
hostname for the connection.
-
#options ⇒ Object
options for the connection.
-
#username ⇒ Object
readonly
username for the connection.
Instance Method Summary collapse
-
#execute(command) ⇒ Integer
Execute command on remote host.
-
#initialize(hostname, username, options = {}) {|self| ... } ⇒ Ssh
constructor
Constructs a new Ssh object.
-
#shutdown ⇒ Object
Shuts down the session connection, if it is still active.
- #to_s ⇒ Object
Constructor Details
#initialize(hostname, username, options = {}) {|self| ... } ⇒ Ssh
Constructs a new Ssh object.
31 32 33 34 35 36 |
# File 'lib/remote-exec/ssh.rb', line 31 def initialize(hostname, username, = {}) @hostname = hostname @username = username = super() end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
hostname for the connection
17 18 19 |
# File 'lib/remote-exec/ssh.rb', line 17 def hostname @hostname end |
#options ⇒ Object
options for the connection
21 22 23 |
# File 'lib/remote-exec/ssh.rb', line 21 def end |
#username ⇒ Object (readonly)
username for the connection
19 20 21 |
# File 'lib/remote-exec/ssh.rb', line 19 def username @username end |
Instance Method Details
#execute(command) ⇒ Integer
Execute command on remote host
57 58 59 60 61 62 63 64 |
# File 'lib/remote-exec/ssh.rb', line 57 def execute(command) # TODO: make it run in one session @last_status = nil @command = command session.open_channel(&method(:execute_open_channel)) session.loop @last_status end |
#shutdown ⇒ Object
Shuts down the session connection, if it is still active.
43 44 45 46 47 48 49 |
# File 'lib/remote-exec/ssh.rb', line 43 def shutdown super return if @session.nil? session.shutdown! ensure @session = nil end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/remote-exec/ssh.rb', line 38 def to_s "<RemoteExec::Ssh @hostname=#{@hostname.inspect}, @username=#{@username.inspect}>" end |