diff options
author | Adam Leff <adam@leff.co> | 2016-12-02 15:07:55 -0500 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-12-02 15:10:20 -0500 |
commit | b3d2b5b6ee62045d391a99752b9b038b01627e91 (patch) | |
tree | 9d2e771a35d56c8c2b9fe6531e2905319b8d0320 /lib/chef | |
parent | 88269ebd629775c625b121709991ebc76d9c0fa4 (diff) | |
download | chef-adamleff/update-ohai-resource.tar.gz |
Update ohai resource to new style, stop overwriting name propertyadamleff/update-ohai-resource
If #5606 is approved, any resource that creates a property that is an
already-existing Ruby method on a Chef::Resource object will throw a
deprecation warning. The ohai resource currently creates a `name`
property which conflicts with the `name` property created in the base
Chef::Resource class.
This change updates the ohai resource and provider to the new style of
defining resources and stops overwriting the `name` method.
Signed-off-by: Adam Leff <adam@leff.co>
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/ohai.rb | 8 | ||||
-rw-r--r-- | lib/chef/resource/ohai.rb | 30 |
2 files changed, 10 insertions, 28 deletions
diff --git a/lib/chef/provider/ohai.rb b/lib/chef/provider/ohai.rb index 6b5a605ed5..8f1939af6d 100644 --- a/lib/chef/provider/ohai.rb +++ b/lib/chef/provider/ohai.rb @@ -21,6 +21,8 @@ require "ohai" class Chef class Provider class Ohai < Chef::Provider + use_inline_resources + provides :ohai def whyrun_supported? @@ -31,7 +33,7 @@ class Chef true end - def action_reload + action :reload do converge_by("re-run ohai and merge results into node attributes") do ohai = ::Ohai::System.new @@ -39,9 +41,9 @@ class Chef # Otherwise it will only reload the specified plugin # Note that any changes to plugins, or new plugins placed on # the path are picked up by ohai. - ohai.all_plugins @new_resource.plugin + ohai.all_plugins new_resource.plugin node.automatic_attrs.merge! ohai.data - Chef::Log.info("#{@new_resource} reloaded") + Chef::Log.info("#{new_resource} reloaded") end end end diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb index 09cd22efc5..6fffecf16e 100644 --- a/lib/chef/resource/ohai.rb +++ b/lib/chef/resource/ohai.rb @@ -20,34 +20,14 @@ class Chef class Resource class Ohai < Chef::Resource + resource_name :ohai + provides :ohai - identity_attr :name - - state_attrs :plugin + property :ohai_name, name_property: true + property :plugin, [String] default_action :reload - - def initialize(name, run_context = nil) - super - @name = name - @plugin = nil - end - - def plugin(arg = nil) - set_or_return( - :plugin, - arg, - :kind_of => [ String ] - ) - end - - def name(arg = nil) - set_or_return( - :name, - arg, - :kind_of => [ String ] - ) - end + allowed_actions :reload end end end |