-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly poll Openstack metadata + other Openstack improvements #818
Changes from 4 commits
5912cc3
85bc7ec
be8c7a9
b18d70f
4c9a5b0
cbca3e0
7809966
c11de20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# | ||
# Author:: Matt Ray (<matt@chef.io>) | ||
# Author:: Tim Smith (<tsmith@chef.io>) | ||
# Copyright:: Copyright (c) 2012-2016 Chef Software, Inc. | ||
# License:: Apache License, Version 2.0 | ||
# | ||
|
@@ -18,53 +19,67 @@ | |
require "ohai/mixin/ec2_metadata" | ||
|
||
Ohai.plugin(:Openstack) do | ||
include Ohai::Mixin::Ec2Metadata | ||
|
||
provides "openstack" | ||
depends "dmi" | ||
depends "etc" | ||
|
||
include Ohai::Mixin::Ec2Metadata | ||
# do we have the openstack dmi data | ||
def openstack_dmi? | ||
# detect a manufacturer of OpenStack Foundation | ||
if dmi[:system][:all_records][0][:Manufacturer] =~ /OpenStack/ | ||
Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == true") | ||
true | ||
end | ||
rescue NoMethodError | ||
Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == false") | ||
false | ||
end | ||
|
||
# check for the ohai hint and log debug messaging | ||
def openstack_hint? | ||
if hint?("openstack") | ||
Ohai::Log.debug("Plugin Openstack: openstack hint present") | ||
return true | ||
else | ||
Ohai::Log.debug("Plugin Openstack: openstack hint not present") | ||
return false | ||
end | ||
end | ||
|
||
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}" | ||
# dreamhost systems hae the dhc-user on them | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
def openstack_provider | ||
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)" | ||
return "dreamhost" if etc["passwd"]["dhc-user"] | ||
rescue NoMethodError | ||
# handle etc not existing on non-linux systems | ||
end | ||
return "openstack" | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. def openstack_provider
if etc["passwd"]["dhc-user"]
"dreamhost"
else
"openstack"
end
rescue NoMethodError
end might be cleaner? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had it that way and it ends up returning nil when it can't find the key, which isn't what you want. Scenarios: |
||
|
||
# grab metadata and return a mash. if we can't connect return nil | ||
def openstack_metadata | ||
metadata = Mash.new | ||
if can_metadata_connect?("169.254.169.254", 80) | ||
fetch_metadata.each do |k, v| | ||
metadata[k] = v | ||
end | ||
rescue => e | ||
Ohai::Log.debug("Encountered error retrieving OpenStack specific metadata (#{uri}), due to #{e.class}") | ||
nil | ||
Ohai::Log.debug("Plugin Openstack: Successfully fetched Openstack metadata from the metadata endpoint") | ||
else | ||
Ohai::Log.debug("Plugin Openstack: Timed out connecting to Openstack metadata endpoint. Skipping metadata.") | ||
end | ||
metadata | ||
end | ||
|
||
collect_data do | ||
# Adds openstack Mash | ||
if hint?("openstack") || hint?("hp") | ||
Ohai::Log.debug("ohai openstack") | ||
|
||
if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) | ||
openstack Mash.new | ||
Ohai::Log.debug("connecting to the OpenStack metadata service") | ||
fetch_metadata.each { |k, v| openstack[k] = v } | ||
|
||
if hint?("hp") | ||
openstack["provider"] = "hp" | ||
else | ||
openstack["provider"] = "openstack" | ||
Ohai::Log.debug("connecting to the OpenStack specific metadata service") | ||
openstack["metadata"] = collect_openstack_metadata | ||
end | ||
|
||
else | ||
Ohai::Log.debug("unable to connect to the OpenStack metadata service") | ||
end | ||
# fetch data if we look like openstack | ||
if openstack_hint? || openstack_dmi? | ||
openstack Mash.new | ||
openstack[:provider] = openstack_provider | ||
openstack[:metadata] = openstack_metadata # fetch metadata or set this to nil | ||
else | ||
Ohai::Log.debug("NOT ohai openstack") | ||
Ohai::Log.debug("Plugin Openstack: Node does not appear to be an Openstack node") | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this can sometimes be "dreamhost"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this one gets a bit weird and here's why I went with openstack. When you're in the context of the cloud plugin says provider you'd think openstack (right? maybe...). When you're in the context of the openstack plugin you know you're openstack so when someone says provider you're thinking about what openstack provider and that could be dreamhost. I guess it could really go either way though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be breaking for some users. Though I understand your argument, I think it's safer to keep it as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous behavior was HP or Openstack, but I'll switch this one back. People on Dreamhost can figure it out probably.