Module: Ohai::Mixin::ScalewayMetadata

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

Instance Method Summary collapse

Instance Method Details

#fetch_metadataHash

fetch scaleway metadata and parse the resulting JSON

Returns:

  • (Hash)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ohai/mixin/scaleway_metadata.rb', line 35

def 
  uri = SCALEWAY_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 ScalewayMetadata: Encountered 404 response retrieving Scaleway metadata: #{uri} ; continuing.")
    {}
  else
    raise "Mixin ScalewayMetadata: Encountered error retrieving Scaleway metadata (#{uri} returned #{response.code} response)"
  end
end

#http_clientNet::HTTP

Returns net/http object without timeout set to 6.

Returns:

  • (Net::HTTP)

    net/http object without timeout set to 6



28
29
30
# File 'lib/ohai/mixin/scaleway_metadata.rb', line 28

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