lib/ohai/plugins/ec2.rb in ohai-16.3.2 vs lib/ohai/plugins/ec2.rb in ohai-16.4.11

- old
+ new

@@ -26,11 +26,10 @@ # 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances Ohai.plugin(:EC2) do require_relative "../mixin/ec2_metadata" require_relative "../mixin/http_helper" - require "base64" include Ohai::Mixin::Ec2Metadata include Ohai::Mixin::HttpHelper provides "ec2" @@ -80,11 +79,11 @@ # this is actually the same value we're looking at in has_ec2_xen_uuid? on # linux hosts # @return [Boolean] do we have a Xen Identifying Number or not? def has_ec2_identifying_number? if RUBY_PLATFORM.match?(/mswin|mingw32|windows/) - require "wmi-lite/wmi" + require "wmi-lite/wmi" unless defined?(WmiLite::Wmi) wmi = WmiLite::Wmi.new if /^ec2/.match?(wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"]) logger.trace("Plugin EC2: has_ec2_identifying_number? == true") true end @@ -113,9 +112,11 @@ return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) end end collect_data do + require "base64" + if looks_like_ec2? logger.trace("Plugin EC2: looks_like_ec2? == true") ec2 Mash.new fetch_metadata.each do |k, v| # fetch_metadata returns IAM security credentials, including the IAM user's