Class: Datacenter::Shell::Remote

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Remote

Returns a new instance of Remote.



40
41
42
# File 'lib/datacenter/shell.rb', line 40

def initialize(*args)
  @options = args
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



38
39
40
# File 'lib/datacenter/shell.rb', line 38

def options
  @options
end

Class Method Details

.open(*args, &block) ⇒ Object



63
64
65
66
67
68
# File 'lib/datacenter/shell.rb', line 63

def self.open(*args, &block)
  shell = new *args
  shell.open
  block.call shell
  shell.close
end

Instance Method Details

#closeObject



56
57
58
59
60
61
# File 'lib/datacenter/shell.rb', line 56

def close
  if @session
    @session.close
    @session = nil
  end
end

#openObject



52
53
54
# File 'lib/datacenter/shell.rb', line 52

def open
  @session = Net::SSH.start *options unless @session
end

#run(command) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/datacenter/shell.rb', line 44

def run(command)
  if @session
    @session.exec!(command).strip
  else
    Net::SSH.start(*options) { |ssh| ssh.exec! command }.to_s.strip
  end
end