lib/ohai/plugins/ec2.rb in ohai-8.16.0 vs lib/ohai/plugins/ec2.rb in ohai-8.17.0

- old
+ new

@@ -36,21 +36,18 @@ depends "kernel" # look for amazon string in dmi bios data # this gets us detection of HVM instances that are within a VPC def has_ec2_dmi? - begin - # detect a version of '4.2.amazon' - if dmi[:bios][:all_records][0][:Version] =~ /amazon/ - Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true") - return true - end - rescue NoMethodError - # dmi[:bios][:all_records][0][:Version] may not exist + # detect a version of '4.2.amazon' + if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/ + Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true") + return true + else + Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false") + return false end - Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false") - return false end # looks for a xen UUID that starts with ec2 # this gets us detection of Linux HVM and Paravirt hosts def has_ec2_xen_uuid? @@ -65,20 +62,17 @@ end # looks for the Amazon.com Organization in Windows Kernel data # this gets us detection of Windows systems def has_amazon_org? - begin - # detect an Organization of 'Amazon.com' - if kernel[:os_info][:organization] =~ /Amazon/ - Ohai::Log.debug("Plugin EC2: has_amazon_org? == true") - return true - end - rescue NoMethodError - # kernel[:os_info][:organization] may not exist + # detect an Organization of 'Amazon.com' + if get_attribute(:kernel, :os_info, :organization) =~ /Amazon/ + Ohai::Log.debug("Plugin EC2: has_amazon_org? == true") + return true + else + Ohai::Log.debug("Plugin EC2: has_amazon_org? == false") + return false end - Ohai::Log.debug("Plugin EC2: has_amazon_org? == false") - return false end def looks_like_ec2? return true if hint?("ec2")