diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-05-11 09:27:11 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-05-11 09:34:08 -0700 |
commit | 758ca032eedf2f801b5f4571aa23242414000f58 (patch) | |
tree | 1f1ef0ebb53b9f3643104784aacc9cab6e69b5ef | |
parent | ab28b87666fadcb62a69dc1fb5c60b23db9b3771 (diff) | |
download | ohai-758ca032eedf2f801b5f4571aa23242414000f58.tar.gz |
Cleanup attribute access in cloud pluginsattribute_cleanup
-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 |