Class: AMI::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/ami/ssh.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ssh) ⇒ SSH

Returns a new instance of SSH.



23
24
25
# File 'lib/ami/ssh.rb', line 23

def initialize(ssh)
  @ssh = ssh
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



32
33
34
# File 'lib/ami/ssh.rb', line 32

def method_missing(method, *args)
  @ssh.send(method, *args)
end

Class Method Details

.create_connection(server, user) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ami/ssh.rb', line 5

def self.create_connection(server, user)
  retries = 5
  begin
    ssh = Gofer::Host.new(server.dns_name, user, :timeout => 30)
    ssh.ls '/' # force gofer to connect to the host
    return AMI::SSH.new(ssh)
  rescue Errno::ECONNREFUSED, Timeout::Error, Errno::EHOSTUNREACH
    retries -= 1
    if retries > 0
      warn "connection attempt failed, #{retries} retries remaining"
      sleep 1
      retry
    else
      raise
    end
  end
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ami/ssh.rb', line 36

def respond_to?(method)
  @ssh.respond_to?(method)
end

#run(command, opts = {}) ⇒ Object



27
28
29
30
# File 'lib/ami/ssh.rb', line 27

def run(command, opts = {})
  puts command
  @ssh.run(command, opts)
end