Class: Facter::EC2::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/ec2/rest.rb

Direct Known Subclasses

Metadata, Userdata

Instance Method Summary collapse

Instance Method Details

#reachable?(retry_limit = 3) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/facter/ec2/rest.rb', line 17

def reachable?(retry_limit = 3)
  timeout = 0.2
  able_to_connect = false
  attempts = 0

  begin
    Timeout.timeout(timeout) do
      open(@baseurl, :proxy => nil).read
    end
    able_to_connect = true
  rescue OpenURI::HTTPError => e
    if e.message.match /404 Not Found/i
      able_to_connect = false
    else
      attempts = attempts + 1
      retry if attempts < retry_limit
    end
  rescue Timeout::Error
    attempts = attempts + 1
    retry if attempts < retry_limit
  rescue *CONNECTION_ERRORS
    attempts = attempts + 1
    retry if attempts < retry_limit
  end

  able_to_connect
end