summaryrefslogtreecommitdiff
path: root/lib/ohai/plugins/openstack.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ohai/plugins/openstack.rb')
-rw-r--r--lib/ohai/plugins/openstack.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index eb357336..28ba3970 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -22,6 +22,26 @@ Ohai.plugin(:Openstack) do
include Ohai::Mixin::Ec2Metadata
+ def collect_openstack_metadata(addr = Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, api_version = '2013-04-04')
+ path = "/openstack/#{api_version}/meta_data.json"
+ uri = "http://#{addr}#{path}"
+ begin
+ response = http_client.get_response(URI.parse(uri),nil,nil)
+ case response.code
+ when '200'
+ FFI_Yajl::Parser.parse(response.body)
+ when '404'
+ Ohai::Log.debug("Encountered 404 response retreiving OpenStack specific metadata path: #{path} ; continuing.")
+ nil
+ else
+ raise "Encountered error retrieving OpenStack specific metadata (#{path} returned #{response.code} response)"
+ end
+ rescue => e
+ Ohai::Log.debug("Encountered error retrieving OpenStack specific metadata (#{uri}), due to #{e.class}")
+ nil
+ end
+ end
+
collect_data do
# Adds openstack Mash
if hint?('openstack') || hint?('hp')
@@ -36,6 +56,8 @@ Ohai.plugin(:Openstack) do
openstack['provider'] = 'hp'
else
openstack['provider'] = 'openstack'
+ Ohai::Log.debug("connecting to the OpenStack specific metadata service")
+ openstack['metadata'] = collect_openstack_metadata
end
else