From c65de79dbd662d895c8a10ef496d7eb9c69376c2 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Fri, 5 Jun 2015 14:01:01 -0700 Subject: Overwrite resource_name with provides --- lib/chef/chef_class.rb | 10 +--- lib/chef/node_map.rb | 35 ++++++++------ lib/chef/platform/resource_priority_map.rb | 4 +- lib/chef/resource.rb | 74 ++++++++++++++++------------- lib/chef/resource/apt_package.rb | 1 - lib/chef/resource/bash.rb | 1 - lib/chef/resource/batch.rb | 1 - lib/chef/resource/bff_package.rb | 1 - lib/chef/resource/breakpoint.rb | 2 - lib/chef/resource/chef_gem.rb | 2 - lib/chef/resource/cookbook_file.rb | 2 - lib/chef/resource/cron.rb | 2 - lib/chef/resource/csh.rb | 1 - lib/chef/resource/deploy.rb | 1 - lib/chef/resource/deploy_revision.rb | 6 --- lib/chef/resource/directory.rb | 2 - lib/chef/resource/dpkg_package.rb | 1 - lib/chef/resource/dsc_resource.rb | 1 - lib/chef/resource/dsc_script.rb | 1 - lib/chef/resource/easy_install_package.rb | 2 - lib/chef/resource/env.rb | 1 - lib/chef/resource/erl_call.rb | 1 - lib/chef/resource/execute.rb | 1 - lib/chef/resource/file.rb | 1 - lib/chef/resource/freebsd_package.rb | 1 - lib/chef/resource/gem_package.rb | 2 - lib/chef/resource/git.rb | 2 - lib/chef/resource/group.rb | 2 - lib/chef/resource/homebrew_package.rb | 1 - lib/chef/resource/http_request.rb | 1 - lib/chef/resource/ifconfig.rb | 1 - lib/chef/resource/ips_package.rb | 1 - lib/chef/resource/link.rb | 2 - lib/chef/resource/log.rb | 1 - lib/chef/resource/macosx_service.rb | 1 - lib/chef/resource/macports_package.rb | 2 - lib/chef/resource/mdadm.rb | 2 - lib/chef/resource/mount.rb | 2 - lib/chef/resource/ohai.rb | 1 - lib/chef/resource/openbsd_package.rb | 1 - lib/chef/resource/package.rb | 2 - lib/chef/resource/pacman_package.rb | 3 -- lib/chef/resource/paludis_package.rb | 2 - lib/chef/resource/perl.rb | 2 - lib/chef/resource/portage_package.rb | 2 - lib/chef/resource/powershell_script.rb | 2 - lib/chef/resource/python.rb | 2 - lib/chef/resource/reboot.rb | 2 - lib/chef/resource/registry_key.rb | 2 - lib/chef/resource/remote_directory.rb | 2 - lib/chef/resource/remote_file.rb | 2 - lib/chef/resource/route.rb | 2 - lib/chef/resource/rpm_package.rb | 2 - lib/chef/resource/ruby.rb | 3 -- lib/chef/resource/ruby_block.rb | 1 - lib/chef/resource/scm.rb | 2 - lib/chef/resource/script.rb | 2 - lib/chef/resource/service.rb | 2 - lib/chef/resource/smartos_package.rb | 3 -- lib/chef/resource/solaris_package.rb | 3 -- lib/chef/resource/subversion.rb | 1 - lib/chef/resource/template.rb | 2 - lib/chef/resource/timestamped_deploy.rb | 1 - lib/chef/resource/user.rb | 3 -- lib/chef/resource/whyrun_safe_ruby_block.rb | 3 -- lib/chef/resource/windows_package.rb | 1 - lib/chef/resource/windows_service.rb | 1 - lib/chef/resource/yum_package.rb | 2 - lib/chef/resource/zypper_package.rb | 4 -- lib/chef/resource_resolver.rb | 31 ++++++++---- 70 files changed, 88 insertions(+), 181 deletions(-) (limited to 'lib') diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb index 1caeee4052..f1dd797c04 100644 --- a/lib/chef/chef_class.rb +++ b/lib/chef/chef_class.rb @@ -162,22 +162,14 @@ class Chef @resource_priority_map = nil end - # - # Removes a resource - # # @api private - def delete_resource_priority_array(name, &filter) - resource_priority_map.delete_priority_array(name, &filter) - end - - private - def provider_priority_map @provider_priority_map ||= begin # these slurp in the resource+provider world, so be exceedingly lazy about requiring them Chef::Platform::ProviderPriorityMap.instance end end + # @api private def resource_priority_map @resource_priority_map ||= begin Chef::Platform::ResourcePriorityMap.instance diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb index 4aed6f94e4..18f55da835 100644 --- a/lib/chef/node_map.rb +++ b/lib/chef/node_map.rb @@ -68,14 +68,13 @@ class Chef # Get a value from the NodeMap via applying the node to the filters that # were set on the key. # - # @param node [Chef::Node] The Chef::Node object for the run + # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to + # ignore all filters. # @param key [Object] Key to look up - # @param canonical [Boolean] Whether to look up only the canonically provided - # DSL (i.e. look up resource_name) # # @return [Object] Value # - def get(node, key, canonical: nil) + def get(node, key) # FIXME: real exception raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil? list(node, key, canonical: canonical).first @@ -85,26 +84,34 @@ class Chef # List all matches for the given node and key from the NodeMap, from # most-recently added to oldest. # - # @param node [Chef::Node] The Chef::Node object for the run + # @param node [Chef::Node] The Chef::Node object for the run, or `nil` to + # ignore all filters. # @param key [Object] Key to look up - # @param canonical [Boolean] Whether to look up only the canonically provided - # DSL (i.e. look up resource_name) # # @return [Object] Value # - def list(node, key, canonical: nil) + def list(node, key) # FIXME: real exception raise "first argument must be a Chef::Node" unless node.is_a?(Chef::Node) || node.nil? return [] unless @map.has_key?(key) @map[key].select do |matcher| - filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block]) && - (!canonical || matcher[:canonical]) + !node || (filters_match?(node, matcher[:filters]) && block_matches?(node, matcher[:block])) end.map { |matcher| matcher[:value] } end + # Seriously, don't use this, it's nearly certain to change on you + # @return remaining # @api private - def delete_if(key, &block) - @map[key].delete_if(&block) + def delete_canonical(key) + remaining = @map[key] + if remaining + remaining.delete_if { |matcher| matcher[:canonical] } + if remaining.empty? + @map.delete(key) + remaining = nil + end + end + remaining end private @@ -142,7 +149,7 @@ class Chef # spend any time here. return true if !filters[attribute] filter_values = Array(filters[attribute]) - value = node ? node[attribute] : nil + value = node[attribute] # Split the blacklist and whitelist blacklist, whitelist = filter_values.partition { |v| v.is_a?(String) && v.start_with?('!') } @@ -159,7 +166,7 @@ class Chef # spend any time here. return true if !filters[attribute] filter_values = Array(filters[attribute]) - value = node ? node[attribute] : nil + value = node[attribute] filter_values.empty? || Array(filter_values).any? do |v| diff --git a/lib/chef/platform/resource_priority_map.rb b/lib/chef/platform/resource_priority_map.rb index eeff843ccf..5d96fd412b 100644 --- a/lib/chef/platform/resource_priority_map.rb +++ b/lib/chef/platform/resource_priority_map.rb @@ -14,8 +14,8 @@ class Chef end # @api private - def delete_priority_array(resource_name, &block) - priority_map.delete_if(resource_name, &block) + def delete_canonical(resource_name) + priority_map.delete_canonical(resource_name) end # @api private diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 5ed85e5869..3a9af0bcca 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -908,24 +908,18 @@ class Chef # # @return [Symbol] The name of this resource type (e.g. `:execute`). # - def self.resource_name(value=NULL_ARG) - + def self.resource_name(name=NULL_ARG) # Setter - if value != NULL_ARG - # Get rid of any current provides - if @resource_name - Chef.delete_resource_priority_array(@resource_name) do |matcher| - Array(matcher[:value]) == [ self ] && matcher[:canonical] - end - if Chef.get_resource_priority_array(@resource_name).nil? - Chef::DSL::Resources.remove_resource_dsl(@resource_name) - end - end - + if name != NULL_ARG # Set the resource_name and call provides - if value - @resource_name = value.to_sym - provides @resource_name, canonical: true + if name + name = name.to_sym + remove_canonical_dsl + # If our class is not already providing this name, provide it. + if !Chef::ResourceResolver.list(name).include?(self) + provides name, canonical: true + end + @resource_name = name else @resource_name = nil end @@ -938,8 +932,8 @@ class Chef @resource_name end - def self.resource_name=(value) - resource_name(value) + def self.resource_name=(name) + resource_name(name) end def self.inherited(child) @@ -947,19 +941,6 @@ class Chef child.resource_name end - # - # Use the class name as the resource name. - # - # Munges the last part of the class name from camel case to snake case, - # and sets the resource_name to that: - # - # A::B::BlahDBlah -> blah_d_blah - # - def self.use_automatic_resource_name - automatic_name = convert_to_snake_case(self.name.split('::')[-1]) - resource_name automatic_name - end - # # The module where Chef should look for providers for this resource. # The provider for `MyResource` will be looked up using @@ -1148,8 +1129,24 @@ class Chef end end - def self.provides(name, opts={}, &block) - result = Chef.set_resource_priority_array(name, self, opts, &block) + # + # Mark this resource as providing particular DSL. + # + # Resources have an automatic DSL based on their resource_name, equivalent to + # `provides :resource_name` (providing the resource on all OS's). If you + # declare a `provides` with the given resource_name, it *replaces* that + # provides (so that you can provide your resource DSL only on certain OS's). + # + def self.provides(name, **options, &block) + name = name.to_sym + + # `provides :resource_name, os: 'linux'`) needs to remove the old + # canonical DSL before adding the new one. + if @resource_name && name == @resource_name + remove_canonical_dsl + end + + result = Chef.set_resource_priority_array(name, self, options, &block) Chef::DSL::Resources.add_resource_dsl(name) result end @@ -1377,6 +1374,17 @@ class Chef end end end + + private + + def self.remove_canonical_dsl + if @resource_name + remaining = Chef.resource_priority_map.delete_canonical(@resource_name) + if !remaining + Chef::DSL::Resources.remove_resource_dsl(@resource_name) + end + end + end end end diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb index 83bb6906d4..ca119b50c4 100644 --- a/lib/chef/resource/apt_package.rb +++ b/lib/chef/resource/apt_package.rb @@ -23,7 +23,6 @@ class Chef class Resource class AptPackage < Chef::Resource::Package - use_automatic_resource_name provides :package, os: "linux", platform_family: [ "debian" ] def initialize(name, run_context=nil) diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb index 554d2de924..025687e879 100644 --- a/lib/chef/resource/bash.rb +++ b/lib/chef/resource/bash.rb @@ -22,7 +22,6 @@ require 'chef/provider/script' class Chef class Resource class Bash < Chef::Resource::Script - use_automatic_resource_name def initialize(name, run_context=nil) super diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb index 8a19e04174..efe3f2205f 100644 --- a/lib/chef/resource/batch.rb +++ b/lib/chef/resource/batch.rb @@ -22,7 +22,6 @@ class Chef class Resource class Batch < Chef::Resource::WindowsScript - use_automatic_resource_name provides :batch, os: "windows" def initialize(name, run_context=nil) diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb index f31fe6a0d8..7c1496a46b 100644 --- a/lib/chef/resource/bff_package.rb +++ b/lib/chef/resource/bff_package.rb @@ -22,7 +22,6 @@ require 'chef/provider/package/aix' class Chef class Resource class BffPackage < Chef::Resource::Package - use_automatic_resource_name end end end diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb index 0107b8968a..69dbc48050 100644 --- a/lib/chef/resource/breakpoint.rb +++ b/lib/chef/resource/breakpoint.rb @@ -22,8 +22,6 @@ require 'chef/resource' class Chef class Resource class Breakpoint < Chef::Resource - use_automatic_resource_name - default_action :break def initialize(action="break", *args) diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb index e4e3ccfbab..0c2fdfa819 100644 --- a/lib/chef/resource/chef_gem.rb +++ b/lib/chef/resource/chef_gem.rb @@ -23,8 +23,6 @@ class Chef class Resource class ChefGem < Chef::Resource::Package::GemPackage - use_automatic_resource_name - def initialize(name, run_context=nil) super @compile_time = Chef::Config[:chef_gem_compile_time] diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb index 08f4733497..42f16e6db6 100644 --- a/lib/chef/resource/cookbook_file.rb +++ b/lib/chef/resource/cookbook_file.rb @@ -27,8 +27,6 @@ class Chef class CookbookFile < Chef::Resource::File include Chef::Mixin::Securable - use_automatic_resource_name - default_action :create def initialize(name, run_context=nil) diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index a399caebe9..93cf41bc37 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -27,8 +27,6 @@ class Chef state_attrs :minute, :hour, :day, :month, :weekday, :user - use_automatic_resource_name - default_action :create allowed_actions :create, :delete diff --git a/lib/chef/resource/csh.rb b/lib/chef/resource/csh.rb index 1c89f2aca6..d5e9c910b1 100644 --- a/lib/chef/resource/csh.rb +++ b/lib/chef/resource/csh.rb @@ -22,7 +22,6 @@ require 'chef/provider/script' class Chef class Resource class Csh < Chef::Resource::Script - use_automatic_resource_name def initialize(name, run_context=nil) super diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb index f88133119a..3e5255bced 100644 --- a/lib/chef/resource/deploy.rb +++ b/lib/chef/resource/deploy.rb @@ -50,7 +50,6 @@ class Chef # release directory. Callback files can contain chef code (resources, etc.) # class Deploy < Chef::Resource - use_automatic_resource_name identity_attr :repository diff --git a/lib/chef/resource/deploy_revision.rb b/lib/chef/resource/deploy_revision.rb index 86a8631ba7..1397359ac8 100644 --- a/lib/chef/resource/deploy_revision.rb +++ b/lib/chef/resource/deploy_revision.rb @@ -22,15 +22,9 @@ class Chef # Convenience class for using the deploy resource with the revision # deployment strategy (provider) class DeployRevision < Chef::Resource::Deploy - - use_automatic_resource_name - end class DeployBranch < Chef::Resource::DeployRevision - - use_automatic_resource_name - end end diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb index 304317e07a..9cac2ce243 100644 --- a/lib/chef/resource/directory.rb +++ b/lib/chef/resource/directory.rb @@ -32,8 +32,6 @@ class Chef include Chef::Mixin::Securable - use_automatic_resource_name - default_action :create allowed_actions :create, :delete diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb index e0b86947f1..38adf24cf6 100644 --- a/lib/chef/resource/dpkg_package.rb +++ b/lib/chef/resource/dpkg_package.rb @@ -23,7 +23,6 @@ class Chef class Resource class DpkgPackage < Chef::Resource::Package - use_automatic_resource_name provides :dpkg_package, os: "linux" end diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index 7c822604e2..5db00f49ca 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -21,7 +21,6 @@ class Chef class Resource class DscResource < Chef::Resource - use_automatic_resource_name provides :dsc_resource, os: "windows" include Chef::DSL::Powershell diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index 0ff7988d7d..2fcf183375 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -22,7 +22,6 @@ class Chef class Resource class DscScript < Chef::Resource - use_automatic_resource_name provides :dsc_script, platform: "windows" default_action :run diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb index 2483b0a8b7..df4cee1ab3 100644 --- a/lib/chef/resource/easy_install_package.rb +++ b/lib/chef/resource/easy_install_package.rb @@ -22,8 +22,6 @@ class Chef class Resource class EasyInstallPackage < Chef::Resource::Package - use_automatic_resource_name - def easy_install_binary(arg=nil) set_or_return( :easy_install_binary, diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index da7d48f062..025bfc72b7 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -25,7 +25,6 @@ class Chef state_attrs :value - use_automatic_resource_name provides :env, os: "windows" default_action :create diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb index b025259b4c..1976c54c45 100644 --- a/lib/chef/resource/erl_call.rb +++ b/lib/chef/resource/erl_call.rb @@ -23,7 +23,6 @@ require 'chef/provider/erl_call' class Chef class Resource class ErlCall < Chef::Resource - use_automatic_resource_name # erl_call : http://erlang.org/doc/man/erl_call.html diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index 34ed6b1bd9..ec669a75d3 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -23,7 +23,6 @@ require 'chef/provider/execute' class Chef class Resource class Execute < Chef::Resource - use_automatic_resource_name identity_attr :command diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index 51969f65a0..d278652cc3 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -47,7 +47,6 @@ class Chef # @returns [String] Checksum of the file we actually rendered attr_accessor :final_checksum - use_automatic_resource_name default_action :create allowed_actions :create, :delete, :touch, :create_if_missing diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index f89e1813b9..c7c43450ba 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -29,7 +29,6 @@ class Chef class FreebsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut - use_automatic_resource_name provides :package, platform: "freebsd" def after_created diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb index 5bd3a89100..b981797876 100644 --- a/lib/chef/resource/gem_package.rb +++ b/lib/chef/resource/gem_package.rb @@ -22,8 +22,6 @@ class Chef class Resource class GemPackage < Chef::Resource::Package - use_automatic_resource_name - def initialize(name, run_context=nil) super @clear_sources = false diff --git a/lib/chef/resource/git.rb b/lib/chef/resource/git.rb index 1229914766..393a0689fe 100644 --- a/lib/chef/resource/git.rb +++ b/lib/chef/resource/git.rb @@ -22,8 +22,6 @@ class Chef class Resource class Git < Chef::Resource::Scm - use_automatic_resource_name - def initialize(name, run_context=nil) super @additional_remotes = Hash[] diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 49cf92a282..2e80f32fea 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -25,8 +25,6 @@ class Chef state_attrs :members - use_automatic_resource_name - allowed_actions :create, :remove, :modify, :manage default_action :create diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb index fe0bd89ced..048ba6b3aa 100644 --- a/lib/chef/resource/homebrew_package.rb +++ b/lib/chef/resource/homebrew_package.rb @@ -25,7 +25,6 @@ class Chef class Resource class HomebrewPackage < Chef::Resource::Package - use_automatic_resource_name provides :package, os: "darwin" def initialize(name, run_context=nil) diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb index 192484f557..f9f056325a 100644 --- a/lib/chef/resource/http_request.rb +++ b/lib/chef/resource/http_request.rb @@ -23,7 +23,6 @@ require 'chef/provider/http_request' class Chef class Resource class HttpRequest < Chef::Resource - use_automatic_resource_name identity_attr :url diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb index 47adc52425..527eb0e515 100644 --- a/lib/chef/resource/ifconfig.rb +++ b/lib/chef/resource/ifconfig.rb @@ -22,7 +22,6 @@ require 'chef/resource' class Chef class Resource class Ifconfig < Chef::Resource - use_automatic_resource_name identity_attr :device diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb index 6b40fe138c..8d720dd411 100644 --- a/lib/chef/resource/ips_package.rb +++ b/lib/chef/resource/ips_package.rb @@ -23,7 +23,6 @@ class Chef class Resource class IpsPackage < ::Chef::Resource::Package - use_automatic_resource_name provides :ips_package, os: "solaris2" allowed_actions :install, :remove, :upgrade diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 2fe4da718c..f932383cc1 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -25,8 +25,6 @@ class Chef class Link < Chef::Resource include Chef::Mixin::Securable - use_automatic_resource_name - identity_attr :target_file state_attrs :to, :owner, :group diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index 5c119df4d8..9adffb26bb 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -23,7 +23,6 @@ require 'chef/provider/log' class Chef class Resource class Log < Chef::Resource - use_automatic_resource_name identity_attr :message diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb index 29da2e6309..f1ed4051cb 100644 --- a/lib/chef/resource/macosx_service.rb +++ b/lib/chef/resource/macosx_service.rb @@ -22,7 +22,6 @@ class Chef class Resource class MacosxService < Chef::Resource::Service - use_automatic_resource_name provides :macosx_service, os: "darwin" provides :service, os: "darwin" diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb index 3ccf831cf2..937839b6e1 100644 --- a/lib/chef/resource/macports_package.rb +++ b/lib/chef/resource/macports_package.rb @@ -19,8 +19,6 @@ class Chef class Resource class MacportsPackage < Chef::Resource::Package - - use_automatic_resource_name provides :package, os: "darwin" end end diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb index 2927cc8321..b789fab155 100644 --- a/lib/chef/resource/mdadm.rb +++ b/lib/chef/resource/mdadm.rb @@ -27,8 +27,6 @@ class Chef state_attrs :devices, :level, :chunk - use_automatic_resource_name - default_action :create allowed_actions :create, :assemble, :stop diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index ce6d2cc232..79986d127f 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -27,8 +27,6 @@ class Chef state_attrs :mount_point, :device_type, :fstype, :username, :password, :domain - use_automatic_resource_name - default_action :mount allowed_actions :mount, :umount, :remount, :enable, :disable diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb index 005b149442..9425e55c0c 100644 --- a/lib/chef/resource/ohai.rb +++ b/lib/chef/resource/ohai.rb @@ -20,7 +20,6 @@ class Chef class Resource class Ohai < Chef::Resource - use_automatic_resource_name identity_attr :name diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb index 1071958cd2..f91fdb37e0 100644 --- a/lib/chef/resource/openbsd_package.rb +++ b/lib/chef/resource/openbsd_package.rb @@ -28,7 +28,6 @@ class Chef class OpenbsdPackage < Chef::Resource::Package include Chef::Mixin::ShellOut - use_automatic_resource_name provides :package, os: "openbsd" def after_created diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb index 4e265c2688..1c6da75678 100644 --- a/lib/chef/resource/package.rb +++ b/lib/chef/resource/package.rb @@ -22,8 +22,6 @@ require 'chef/resource' class Chef class Resource class Package < Chef::Resource - use_automatic_resource_name - identity_attr :package_name state_attrs :version, :options diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb index 222fb3c78e..54b8efc4c2 100644 --- a/lib/chef/resource/pacman_package.rb +++ b/lib/chef/resource/pacman_package.rb @@ -21,10 +21,7 @@ require 'chef/resource/package' class Chef class Resource class PacmanPackage < Chef::Resource::Package - - use_automatic_resource_name provides :pacman_package, os: "linux" - end end end diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb index f0ddc5927a..56c47bc141 100644 --- a/lib/chef/resource/paludis_package.rb +++ b/lib/chef/resource/paludis_package.rb @@ -22,8 +22,6 @@ require 'chef/provider/package/paludis' class Chef class Resource class PaludisPackage < Chef::Resource::Package - - use_automatic_resource_name provides :paludis_package, os: "linux" allowed_actions :install, :remove, :upgrade diff --git a/lib/chef/resource/perl.rb b/lib/chef/resource/perl.rb index 6870f487eb..773eba6571 100644 --- a/lib/chef/resource/perl.rb +++ b/lib/chef/resource/perl.rb @@ -22,8 +22,6 @@ require 'chef/provider/script' class Chef class Resource class Perl < Chef::Resource::Script - use_automatic_resource_name - def initialize(name, run_context=nil) super @interpreter = "perl" diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb index 009a525d22..1af48702fa 100644 --- a/lib/chef/resource/portage_package.rb +++ b/lib/chef/resource/portage_package.rb @@ -21,8 +21,6 @@ require 'chef/resource/package' class Chef class Resource class PortagePackage < Chef::Resource::Package - use_automatic_resource_name - def initialize(name, run_context=nil) super @provider = Chef::Provider::Package::Portage diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb index a3a24fce7f..7d432883e4 100644 --- a/lib/chef/resource/powershell_script.rb +++ b/lib/chef/resource/powershell_script.rb @@ -20,8 +20,6 @@ require 'chef/resource/windows_script' class Chef class Resource class PowershellScript < Chef::Resource::WindowsScript - - use_automatic_resource_name provides :powershell_script, os: "windows" def initialize(name, run_context=nil) diff --git a/lib/chef/resource/python.rb b/lib/chef/resource/python.rb index 5c120d7d27..432ee46b85 100644 --- a/lib/chef/resource/python.rb +++ b/lib/chef/resource/python.rb @@ -21,8 +21,6 @@ require 'chef/provider/script' class Chef class Resource class Python < Chef::Resource::Script - use_automatic_resource_name - def initialize(name, run_context=nil) super @interpreter = "python" diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index 216367692f..401f2f338f 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -24,8 +24,6 @@ require 'chef/resource' class Chef class Resource class Reboot < Chef::Resource - use_automatic_resource_name - allowed_actions :request_reboot, :reboot_now, :cancel def initialize(name, run_context=nil) diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index 9ee031b751..4ed0d4a4e0 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -22,8 +22,6 @@ require 'chef/digester' class Chef class Resource class RegistryKey < Chef::Resource - use_automatic_resource_name - identity_attr :key state_attrs :values diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index bb052d3bd4..b731f7b201 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -26,8 +26,6 @@ class Chef class RemoteDirectory < Chef::Resource::Directory include Chef::Mixin::Securable - use_automatic_resource_name - identity_attr :path state_attrs :files_owner, :files_group, :files_mode diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 99c21cae52..b7a553cbe8 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -28,8 +28,6 @@ class Chef class RemoteFile < Chef::Resource::File include Chef::Mixin::Securable - use_automatic_resource_name - def initialize(name, run_context=nil) super @source = [] diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb index 3df767a128..3ba8f6215b 100644 --- a/lib/chef/resource/route.rb +++ b/lib/chef/resource/route.rb @@ -22,8 +22,6 @@ require 'chef/resource' class Chef class Resource class Route < Chef::Resource - use_automatic_resource_name - identity_attr :target state_attrs :netmask, :gateway diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb index 67a6c156d8..b8b5144a42 100644 --- a/lib/chef/resource/rpm_package.rb +++ b/lib/chef/resource/rpm_package.rb @@ -22,8 +22,6 @@ require 'chef/provider/package/rpm' class Chef class Resource class RpmPackage < Chef::Resource::Package - - use_automatic_resource_name provides :rpm_package, os: [ "linux", "aix" ] def initialize(name, run_context=nil) diff --git a/lib/chef/resource/ruby.rb b/lib/chef/resource/ruby.rb index 759955da42..3c3909043d 100644 --- a/lib/chef/resource/ruby.rb +++ b/lib/chef/resource/ruby.rb @@ -22,13 +22,10 @@ require 'chef/provider/script' class Chef class Resource class Ruby < Chef::Resource::Script - use_automatic_resource_name - def initialize(name, run_context=nil) super @interpreter = "ruby" end - end end end diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb index 4ce7b2cee1..ae8e4cb7cd 100644 --- a/lib/chef/resource/ruby_block.rb +++ b/lib/chef/resource/ruby_block.rb @@ -23,7 +23,6 @@ require 'chef/provider/ruby_block' class Chef class Resource class RubyBlock < Chef::Resource - use_automatic_resource_name default_action :run allowed_actions :create, :run diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb index 8379a3d8a9..85028c266b 100644 --- a/lib/chef/resource/scm.rb +++ b/lib/chef/resource/scm.rb @@ -22,8 +22,6 @@ require 'chef/resource' class Chef class Resource class Scm < Chef::Resource - use_automatic_resource_name - identity_attr :destination state_attrs :revision diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb index f3d3ef01f4..30bed367cb 100644 --- a/lib/chef/resource/script.rb +++ b/lib/chef/resource/script.rb @@ -23,8 +23,6 @@ require 'chef/provider/script' class Chef class Resource class Script < Chef::Resource::Execute - use_automatic_resource_name - # Chef-13: go back to using :name as the identity attr identity_attr :command diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 9995eccb3f..aa59b543be 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -22,8 +22,6 @@ require 'chef/resource' class Chef class Resource class Service < Chef::Resource - use_automatic_resource_name - identity_attr :service_name state_attrs :enabled, :running diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb index 7460f0f687..b8bd940c24 100644 --- a/lib/chef/resource/smartos_package.rb +++ b/lib/chef/resource/smartos_package.rb @@ -22,10 +22,7 @@ require 'chef/provider/package/smartos' class Chef class Resource class SmartosPackage < Chef::Resource::Package - - use_automatic_resource_name provides :package, os: "solaris2", platform_family: "smartos" - end end end diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb index 545e783b75..2dc72d5c47 100644 --- a/lib/chef/resource/solaris_package.rb +++ b/lib/chef/resource/solaris_package.rb @@ -23,14 +23,11 @@ require 'chef/provider/package/solaris' class Chef class Resource class SolarisPackage < Chef::Resource::Package - - use_automatic_resource_name provides :package, os: "solaris2", platform_family: "nexentacore" provides :package, os: "solaris2", platform_family: "solaris2" do |node| # on >= Solaris 11 we default to IPS packages instead node[:platform_version].to_f <= 5.10 end - end end end diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb index e12d939ca6..ae6a37caa2 100644 --- a/lib/chef/resource/subversion.rb +++ b/lib/chef/resource/subversion.rb @@ -22,7 +22,6 @@ require "chef/resource/scm" class Chef class Resource class Subversion < Chef::Resource::Scm - use_automatic_resource_name allowed_actions :force_export def initialize(name, run_context=nil) diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb index a8e38aa5fb..5a7f7efd6f 100644 --- a/lib/chef/resource/template.rb +++ b/lib/chef/resource/template.rb @@ -27,8 +27,6 @@ class Chef class Template < Chef::Resource::File include Chef::Mixin::Securable - use_automatic_resource_name - attr_reader :inline_helper_blocks attr_reader :inline_helper_modules diff --git a/lib/chef/resource/timestamped_deploy.rb b/lib/chef/resource/timestamped_deploy.rb index 15ac296f78..344f8b0a5e 100644 --- a/lib/chef/resource/timestamped_deploy.rb +++ b/lib/chef/resource/timestamped_deploy.rb @@ -21,7 +21,6 @@ class Chef # Convenience class for using the deploy resource with the timestamped # deployment strategy (provider) class TimestampedDeploy < Chef::Resource::Deploy - use_automatic_resource_name end end end diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index 66c183ad7e..b85b648c92 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -21,13 +21,10 @@ require 'chef/resource' class Chef class Resource class User < Chef::Resource - identity_attr :username state_attrs :uid, :gid, :home - use_automatic_resource_name - default_action :create allowed_actions :create, :remove, :modify, :manage, :lock, :unlock diff --git a/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb index 0ade9c981f..f289f15001 100644 --- a/lib/chef/resource/whyrun_safe_ruby_block.rb +++ b/lib/chef/resource/whyrun_safe_ruby_block.rb @@ -19,9 +19,6 @@ class Chef class Resource class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock - - use_automatic_resource_name - end end end diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb index bcf288e7b2..a76765cc36 100644 --- a/lib/chef/resource/windows_package.rb +++ b/lib/chef/resource/windows_package.rb @@ -26,7 +26,6 @@ class Chef class WindowsPackage < Chef::Resource::Package include Chef::Mixin::Uris - use_automatic_resource_name provides :windows_package, os: "windows" provides :package, os: "windows" diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 099042840c..a77690652e 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -25,7 +25,6 @@ class Chef # Until #1773 is resolved, you need to manually specify the windows_service resource # to use action :configure_startup and attribute startup_type - use_automatic_resource_name provides :windows_service, os: "windows" provides :service, os: "windows" diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb index ae9c840582..4d54f6051f 100644 --- a/lib/chef/resource/yum_package.rb +++ b/lib/chef/resource/yum_package.rb @@ -22,8 +22,6 @@ require 'chef/provider/package/yum' class Chef class Resource class YumPackage < Chef::Resource::Package - - use_automatic_resource_name provides :package, os: "linux", platform_family: [ "rhel", "fedora" ] def initialize(name, run_context=nil) diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb index 74cdf72e15..f09a20e2c6 100644 --- a/lib/chef/resource/zypper_package.rb +++ b/lib/chef/resource/zypper_package.rb @@ -21,11 +21,7 @@ require 'chef/resource/package' class Chef class Resource class ZypperPackage < Chef::Resource::Package - provides :package, platform_family: "suse" - - use_automatic_resource_name - end end end diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb index 12618d693b..22fed7e587 100644 --- a/lib/chef/resource_resolver.rb +++ b/lib/chef/resource_resolver.rb @@ -28,10 +28,9 @@ class Chef attr_reader :action attr_reader :canonical - def initialize(node, resource, canonical: nil) + def initialize(node, resource) @node = node @resource = resource.to_sym - @canonical = canonical end def resolve @@ -49,6 +48,12 @@ class Chef handler end + def list + Chef::Log.debug "Resources for generic #{resource} resource enabled on node include: #{enabled_handlers}" + Chef::Log.debug "Resources for #{resource}: #{prioritized_handlers}" + prioritized_handlers + end + def provided_by?(resource_class) !prioritized_handlers.include?(resource_class) end @@ -56,14 +61,24 @@ class Chef # # Resolve a resource by name. # - # @param resource_name [Symbol] The resource DSL name (e.g. `:file`) + # @param resource_name [Symbol] The resource DSL name (e.g. `:file`). # @param node [Chef::Node] The node on which the resource will run. If not # passed, will return the first match. - # @param canonical [Boolean] Whether to restrict the search to the canonical - # name (the one set by `resource_name`) # - def self.resolve(resource_name, node: Chef.node, canonical: false) - new(node, resource_name, canonical: canonical).resolve + def self.resolve(resource_name, node: nil) + new(node, resource_name).resolve + end + + # + # Resolve a list of all resources that implement the given DSL (in order of + # preference). + # + # @param resource_name [Symbol] The resource DSL name (e.g. `:file`). + # @param node [Chef::Node] The node on which the resource will run. If not + # passed, will return all resources (ignoring filters). + # + def self.list(resource_name, node: nil) + new(node, resource_name).list end protected @@ -74,7 +89,7 @@ class Chef def prioritized_handlers @prioritized_handlers ||= - priority_map.list_handlers(node, resource, canonical: nil) + priority_map.list_handlers(node, resource) end module Deprecated -- cgit v1.2.1