Class: Datacenter::Shell::Ssh
- Inherits:
-
Object
- Object
- Datacenter::Shell::Ssh
- Defined in:
- lib/datacenter/shell.rb
Instance Attribute Summary collapse
-
#ssh_args ⇒ Object
readonly
Returns the value of attribute ssh_args.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(*args) ⇒ Ssh
constructor
A new instance of Ssh.
- #open ⇒ Object
- #run(command) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Ssh
Returns a new instance of Ssh.
13 14 15 |
# File 'lib/datacenter/shell.rb', line 13 def initialize(*args) @ssh_args = args end |
Instance Attribute Details
#ssh_args ⇒ Object (readonly)
Returns the value of attribute ssh_args.
11 12 13 |
# File 'lib/datacenter/shell.rb', line 11 def ssh_args @ssh_args end |
Class Method Details
.open(*args, &block) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/datacenter/shell.rb', line 36 def self.open(*args, &block) shell = new *args shell.open block.call shell shell.close end |
Instance Method Details
#close ⇒ Object
29 30 31 32 33 34 |
# File 'lib/datacenter/shell.rb', line 29 def close if @session @session.close @session = nil end end |
#open ⇒ Object
25 26 27 |
# File 'lib/datacenter/shell.rb', line 25 def open @session = Net::SSH.start *@ssh_args unless @session end |
#run(command) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/datacenter/shell.rb', line 17 def run(command) if @session @session.exec!(command).strip else Net::SSH.start(*@ssh_args) { |ssh| ssh.exec! command }.strip end end |