Module Ohai::Mixin::Ec2Metadata
In: lib/ohai/mixin/ec2_metadata.rb

This code parses the EC2 Instance Metadata API to provide details of the running instance.

Earlier version of this code assumed a specific version of the metadata API was available. Unfortunately the API versions supported by a particular instance are determined at instance launch and are not extended over the life of the instance. As such the earlier code would fail depending on the age of the instance.

The updated code probes the instance metadata endpoint for available versions, determines the most advanced version known to work and executes the metadata retrieval using that version.

If no compatible version is found, an empty hash is returned.

Methods

Constants

EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR)
EC2_SUPPORTED_VERSIONS = %w[ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15 2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12 ]
EC2_ARRAY_VALUES = %w(security-groups)
EC2_ARRAY_DIR = %w(network/interfaces/macs)
EC2_JSON_DIR = %w(iam)

Public Instance methods

Get metadata for a given path and API version

@details

  Typically, a 200 response is expected for valid metadata.
  On certain instance types, traversing the provided metadata path
  produces a 404 for some unknown reason. In that event, return
  `nil` and continue the run instead of failing it.

[Validate]