summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-05-09 20:58:45 -0700
committerTim Smith <tsmith@chef.io>2017-02-23 12:57:31 -0800
commitd1906045a7ebd748fcabc8e937504dc8d659a669 (patch)
tree99e0085e4f6998b53871ef1ba69768445832b63f
parent0c2f4416c7a9de5d4cce7337036ee4db3a4f4ac3 (diff)
downloadohai-d1906045a7ebd748fcabc8e937504dc8d659a669.tar.gz
Detect DigitalOcean via DMI data
The cloud data on the droplet I spun up didn't have the string listed and it also required disk reads / yaml to be loaded. This should be a lot faster since we're grabbing this data anyways.
-rw-r--r--lib/ohai/plugins/digital_ocean.rb28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/ohai/plugins/digital_ocean.rb b/lib/ohai/plugins/digital_ocean.rb
index d6309c0d..eaabfb7d 100644
--- a/lib/ohai/plugins/digital_ocean.rb
+++ b/lib/ohai/plugins/digital_ocean.rb
@@ -16,34 +16,34 @@
# limitations under the License.
require "ohai/mixin/do_metadata"
-require "yaml"
Ohai.plugin(:DigitalOcean) do
include Ohai::Mixin::DOMetadata
- DO_CLOUD_INIT_FILE = "/etc/cloud/cloud.cfg" unless defined?(DO_CLOUD_INIT_FILE)
-
provides "digital_ocean"
depends "network/interfaces"
-
- def has_do_init?
- if File.exist?(DO_CLOUD_INIT_FILE)
- datasource = YAML.load_file(DO_CLOUD_INIT_FILE)
- if datasource["datasource_list"].include?("DigitalOcean")
- Ohai::Log.debug("Plugin DigitalOcean: has_do_init? == true")
- true
+ depends "dmi"
+
+ # look for digitalocean string in dmi bios data
+ def has_do_dmi?
+ begin
+ # detect a vendor of "DigitalOcean"
+ if dmi[:bios][:all_records][0][:Vendor] == "DigitalOcean"
+ Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == true")
+ return true
end
- else
- Ohai::Log.debug("Plugin DigitalOcean: has_do_init? == false")
- false
+ rescue NoMethodError
+ # dmi[:bios][:all_records][0][:Vendor] may not exist
end
+ Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == false")
+ return false
end
def looks_like_digital_ocean?
return true if hint?("digital_ocean")
- if has_do_init?
+ if has_do_dmi?
return true if can_metadata_connect?(Ohai::Mixin::DOMetadata::DO_METADATA_ADDR, 80)
end
end