diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-17 12:33:28 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-17 12:35:58 -0700 |
commit | ddb93d1d20205565fd7092e2fdeca3efddb00698 (patch) | |
tree | 36d5ed77cb294ed204d3711b920c1e4c038aaef5 /lib/chef/platform | |
parent | a1f9544e2ad149febbdd3e9acaacfec0323c20dd (diff) | |
download | chef-ddb93d1d20205565fd7092e2fdeca3efddb00698.tar.gz |
Chef-13: remove Chef::Platform.set and related methods
Switch over the Chef-12.0 ProviderResolver is now completed.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/platform')
-rw-r--r-- | lib/chef/platform/provider_mapping.rb | 166 |
1 files changed, 1 insertions, 165 deletions
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb index 55e831c343..ed65a8a715 100644 --- a/lib/chef/platform/provider_mapping.rb +++ b/lib/chef/platform/provider_mapping.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,45 +26,8 @@ class Chef class Platform class << self - attr_writer :platforms - - def platforms - @platforms ||= { default: {} } - end - include Chef::Mixin::ParamsValidate - def find(name, version) - Chef.deprecated(:chef_platform_methods, "#{self.name}.find is deprecated") - provider_map = platforms[:default].clone - - name_sym = name - if name.kind_of?(String) - name = name.downcase - name.gsub!(/\s/, "_") - name_sym = name.to_sym - end - - if platforms.has_key?(name_sym) - platform_versions = platforms[name_sym].select { |k, v| k != :default } - if platforms[name_sym].has_key?(:default) - provider_map.merge!(platforms[name_sym][:default]) - end - platform_versions.each do |platform_version, provider| - begin - version_constraint = Chef::VersionConstraint::Platform.new(platform_version) - if version_constraint.include?(version) - Chef::Log.debug("Platform #{name} version #{version} found") - provider_map.merge!(provider) - end - rescue Chef::Exceptions::InvalidPlatformVersion - Chef::Log.debug("Chef::Version::Comparable does not know how to parse the platform version: #{version}") - end - end - end - provider_map - end - def find_platform_and_version(node) platform = nil version = nil @@ -90,133 +53,6 @@ class Chef [platform, version] end - def provider_for_resource(resource, action = :nothing) - Chef.deprecated(:chef_platform_methods, "#{name}.provider_for_resource is deprecated") - node = resource.run_context && resource.run_context.node - raise ArgumentError, "Cannot find the provider for a resource with no run context set" unless node - provider = find_provider_for_node(node, resource).new(resource, resource.run_context) - provider.action = action - provider - end - - def provider_for_node(node, resource_type) - raise NotImplementedError, "#{name} no longer supports #provider_for_node" - end - - def find_provider_for_node(node, resource_type) - Chef.deprecated(:chef_platform_methods, "#{name}.find_provider_for_node is deprecated") - platform, version = find_platform_and_version(node) - find_provider(platform, version, resource_type) - end - - def set(args) - Chef.deprecated(:chef_platform_methods, "#{name}.set is deprecated") - validate( - args, - { - :platform => { - :kind_of => Symbol, - :required => false, - }, - :version => { - :kind_of => String, - :required => false, - }, - :resource => { - :kind_of => Symbol, - }, - :provider => { - :kind_of => [ String, Symbol, Class ], - }, - } - ) - if args.has_key?(:platform) - if args.has_key?(:version) - if platforms.has_key?(args[:platform]) - if platforms[args[:platform]].has_key?(args[:version]) - platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider] - else - platforms[args[:platform]][args[:version]] = { - args[:resource].to_sym => args[:provider], - } - end - else - platforms[args[:platform]] = { - args[:version] => { - args[:resource].to_sym => args[:provider], - }, - } - end - else - if platforms.has_key?(args[:platform]) - if platforms[args[:platform]].has_key?(:default) - platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider] - elsif args[:platform] == :default - platforms[:default][args[:resource].to_sym] = args[:provider] - else - platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } } - end - else - platforms[args[:platform]] = { - :default => { - args[:resource].to_sym => args[:provider], - }, - } - end - end - else - if platforms.has_key?(:default) - platforms[:default][args[:resource].to_sym] = args[:provider] - else - platforms[:default] = { - args[:resource].to_sym => args[:provider], - } - end - end - end - - def find_provider(platform, version, resource_type) - Chef.deprecated(:chef_platform_methods, "#{name}.find_provider is deprecated") - provider_klass = explicit_provider(platform, version, resource_type) || - platform_provider(platform, version, resource_type) || - resource_matching_provider(platform, version, resource_type) - - raise Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil? - - provider_klass - end - - private - - def explicit_provider(platform, version, resource_type) - resource_type.kind_of?(Chef::Resource) ? resource_type.provider : nil - end - - def platform_provider(platform, version, resource_type) - pmap = Chef::Platform.find(platform, version) - rtkey = resource_type.kind_of?(Chef::Resource) ? resource_type.resource_name.to_sym : resource_type - pmap.has_key?(rtkey) ? pmap[rtkey] : nil - end - - include Chef::Mixin::ConvertToClassName - - def resource_matching_provider(platform, version, resource_type) - if resource_type.kind_of?(Chef::Resource) - class_name = if resource_type.class.name - resource_type.class.name.split("::").last - else - convert_to_class_name(resource_type.resource_name.to_s) - end - - if Chef::Provider.const_defined?(class_name, false) - Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.") - Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to use the resource's DSL.") - return Chef::Provider.const_get(class_name, false) - end - end - nil - end - end end end |