module Ohai::Mixin::AzureMetadata
Constants
- AZURE_METADATA_ADDR
- AZURE_METADATA_URL
Public Instance Methods
fetch_metadata()
click to toggle source
# File lib/ohai/mixin/azure_metadata.rb, line 34 def fetch_metadata Ohai::Log.debug("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 Ohai::Log.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON") nil end else Ohai::Log.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, initheader = { "Metadata" => "true" }) end