Class: Datacenter::Shell::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/datacenter/shell/remote.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#closeObject



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

#openObject



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, options={})
  if session
    run! command, options
  else
    self.class.open(*args) { |shell| shell.run command, options }
  end
end