lib/ohai/plugins/ec2.rb in ohai-8.9.0 vs lib/ohai/plugins/ec2.rb in ohai-8.10.0

- old
+ new

@@ -24,11 +24,13 @@ include Ohai::Mixin::Ec2Metadata provides "ec2" depends "network/interfaces" + depends "dmi" + # look for arp address that non-VPC hosts will have def has_ec2_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? if iface[:arp].value?("fe:ff:ff:ff:ff:ff") Ohai::Log.debug("has_ec2_mac? == true") @@ -38,14 +40,30 @@ end Ohai::Log.debug("has_ec2_mac? == false") false end + # look for amazon string in dmi bios data + # this only works on hvm instances as paravirt instances have no dmi data + def has_ec2_dmi? + begin + # detect a version of '4.2.amazon' + if dmi[:bios][:all_records][0][:Version] =~ /amazon/ + Ohai::Log.debug("has_ec2_dmi? == true") + true + end + rescue NoMethodError + Ohai::Log.debug("has_ec2_dmi? == false") + false + end + end + + def looks_like_ec2? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 - hint?('ec2') || has_ec2_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80) + hint?('ec2') || ( has_ec2_dmi? || has_ec2_mac?) && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80) end collect_data do if looks_like_ec2? Ohai::Log.debug("looks_like_ec2? == true") @@ -58,10 +76,10 @@ next if k == 'iam' && !hint?('iam') ec2[k] = v end ec2[:userdata] = self.fetch_userdata #ASCII-8BIT is equivalent to BINARY in this case - if ec2[:userdata].encoding.to_s == "ASCII-8BIT" + if ec2[:userdata] && ec2[:userdata].encoding.to_s == "ASCII-8BIT" Ohai::Log.debug("Binary UserData Found. Storing in base64") ec2[:userdata] = Base64.encode64(ec2[:userdata]) end else Ohai::Log.debug("looks_like_ec2? == false")