module Ohai::Mixin::AzureMetadata

Public Instance Methods

fetch_metadata() click to toggle source
# File lib/ohai/mixin/azure_metadata.rb, line 34
def fetch_metadata
  logger.trace("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}")
  response = http_get(AZURE_METADATA_URL)
  if response.code == "200"
    begin
      data = StringIO.new(response.body)
      parser = FFI_Yajl::Parser.new
      parser.parse(data)
    rescue FFI_Yajl::ParseError
      logger.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
      nil
    end
  else
    logger.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata")
    nil
  end
end
http_get(uri) click to toggle source

fetch the meta content with a timeout and the required header

# File lib/ohai/mixin/azure_metadata.rb, line 28
def http_get(uri)
  conn = Net::HTTP.start(AZURE_METADATA_ADDR)
  conn.read_timeout = 6
  conn.get(uri, { "Metadata" => "true" })
end