summaryrefslogtreecommitdiff
path: root/lib/chef/provider_resolver.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/provider_resolver.rb')
-rw-r--r--lib/chef/provider_resolver.rb38
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb
index 5ffd8da900..c0a537624e 100644
--- a/lib/chef/provider_resolver.rb
+++ b/lib/chef/provider_resolver.rb
@@ -17,6 +17,7 @@
#
require 'chef/exceptions'
+require 'chef/platform/provider_priority_map'
class Chef
class ProviderResolver
@@ -48,25 +49,33 @@ class Chef
# try dynamically finding a provider based on querying the providers to see what they support
def maybe_dynamic_provider_resolution(resource, action)
- handlers = providers.select do |klass|
+ # this cut only depends on the node value and is going to be static for all nodes
+ # will contain all providers that could possibly support a resource on a node
+ enabled_handlers = providers.select do |klass|
klass.provides?(node, resource)
end
- # log this so we know what providers will work for the generic resource on the node
- Chef::Log.debug "providers for generic #{resource.resource_name} resource enabled on node include: #{handlers}"
+ # log this so we know what providers will work for the generic resource on the node (early cut)
+ Chef::Log.debug "providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}"
- handlers.select! do |klass|
+ # ask all the enabled providers if they can actually support the resource
+ supported_handlers = enabled_handlers.select do |klass|
klass.handles?(resource, action)
end
- # log this separately from above so we know what providers were excluded by config
- Chef::Log.debug "providers that support resource #{resource} include: #{handlers}"
+ # what providers were excluded by machine state (late cut)
+ Chef::Log.debug "providers that refused resource #{resource} were: #{enabled_handlers - supported_handlers}"
+ Chef::Log.debug "providers that support resource #{resource} include: #{supported_handlers}"
- # classes can declare that they replace other classes, gather them all
- replacements = handlers.map { |klass| klass.replaces }.flatten
+ handlers = supported_handlers.empty? ? enabled_handlers : supported_handlers
- # reject all the classes that have been replaced
- handlers -= replacements
+ if handlers.count >= 2
+ priority_list = [ get_provider_priority_map(resource.resource_name, node) ].flatten.compact
+
+ handlers = handlers.sort_by { |x| i = priority_list.index x; i.nil? ? Float::INFINITY : i }
+
+ handlers = [ handlers.first ]
+ end
Chef::Log.debug "providers that survived replacement include: #{handlers}"
@@ -81,5 +90,14 @@ class Chef
def maybe_chef_platform_lookup(resource)
Chef::Platform.find_provider_for_node(node, resource)
end
+
+ # dep injection hooks
+ def get_provider_priority_map(resource_name, node)
+ provider_priority_map.get(node, resource_name)
+ end
+
+ def provider_priority_map
+ Chef::Platform::ProviderPriorityMap.instance.priority_map
+ end
end
end