diff options
author | Thom May <thom@may.lt> | 2016-05-31 08:10:11 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-05-31 08:10:11 +0100 |
commit | dae2bd55cc1540e770e858e1f6e9637c3cb3ec6e (patch) | |
tree | d7902759831dea3ee7380ed4e42f5d91b2b242e7 | |
parent | dd350ddd38d9976892a7754d142b2b6e707a9f56 (diff) | |
parent | 758ca032eedf2f801b5f4571aa23242414000f58 (diff) | |
download | ohai-dae2bd55cc1540e770e858e1f6e9637c3cb3ec6e.tar.gz |
Merge pull request #821 from chef/attribute_cleanup
Cleanup attribute access in cloud plugins
-rw-r--r-- | lib/ohai/plugins/ec2.rb | 34 | ||||
-rw-r--r-- | lib/ohai/plugins/openstack.rb | 16 |
2 files changed, 20 insertions, 30 deletions
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index 0902c781..c7f78568 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -38,17 +38,14 @@ Ohai.plugin(:EC2) do # 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 @@ -67,17 +64,14 @@ Ohai.plugin(:EC2) do # 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? diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb index 3b6fba30..a7818e60 100644 --- a/lib/ohai/plugins/openstack.rb +++ b/lib/ohai/plugins/openstack.rb @@ -28,13 +28,13 @@ Ohai.plugin(:Openstack) do # do we have the openstack dmi data def openstack_dmi? # detect a manufacturer of OpenStack Foundation - if dmi[:system][:all_records][0][:Manufacturer] =~ /OpenStack/ + if get_attribute(:dmi, :system, :all_records, 0, :Manufacturer) =~ /OpenStack/ Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == true") - true + return true + else + Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == false") + return false end - rescue NoMethodError - Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == false") - false end # check for the ohai hint and log debug messaging @@ -50,11 +50,7 @@ Ohai.plugin(:Openstack) do # dreamhost systems have the dhc-user on them def openstack_provider - begin - return "dreamhost" if etc["passwd"]["dhc-user"] - rescue NoMethodError - # handle etc not existing on non-linux systems - end + return "dreamhost" if get_attribute("etc", "passwd", "dhc-user") return "openstack" end |