Class: Datacenter::Shell::Remote
- Inherits:
-
Object
- Object
- Datacenter::Shell::Remote
- Defined in:
- lib/datacenter/shell/remote.rb
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(*args) ⇒ Remote
constructor
A new instance of Remote.
- #open ⇒ Object
- #run(command, options = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Remote
Returns a new instance of Remote.
5 6 7 |
# File 'lib/datacenter/shell/remote.rb', line 5 def initialize(*args) @args = args end |
Class Method Details
.open(*args) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/datacenter/shell/remote.rb', line 28 def self.open(*args) shell = new *args shell.open yield shell ensure shell.close end |
Instance Method Details
#close ⇒ Object
13 14 15 16 17 18 |
# File 'lib/datacenter/shell/remote.rb', line 13 def close if session && !session.closed? session.close @session = nil end end |
#open ⇒ Object
9 10 11 |
# File 'lib/datacenter/shell/remote.rb', line 9 def open @session ||= Net::SSH.start *args end |
#run(command, options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/datacenter/shell/remote.rb', line 20 def run(command, ={}) if session run! command, else self.class.open(*args) { |shell| shell.run command, } end end |