Module: Ohai::Mixin::DOMetadata

Defined in:
lib/ohai/mixin/do_metadata.rb

Instance Method Summary collapse

Instance Method Details

#fetch_metadataObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ohai/mixin/do_metadata.rb', line 31

def 
  uri = DO_METADATA_URL.to_s
  response = http_client.get(uri)
  case response.code
  when "200"
    parser = FFI_Yajl::Parser.new
    parser.parse(response.body)
  when "404"
    logger.trace("Mixin DOMetadata: Encountered 404 response retrieving Digital Ocean metadata: #{uri} ; continuing.")
    {}
  else
    raise "Mixin DOMetadata: Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)"
  end
end

#http_clientObject



27
28
29
# File 'lib/ohai/mixin/do_metadata.rb', line 27

def http_client
  Net::HTTP.start(DO_METADATA_ADDR).tap { |h| h.read_timeout = 6 }
end