chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +12 -1
- data/lib/chef/api_client.rb +130 -26
- data/lib/chef/application.rb +0 -1
- data/lib/chef/application/client.rb +8 -19
- data/lib/chef/audit/audit_reporter.rb +12 -7
- data/lib/chef/audit/logger.rb +36 -0
- data/lib/chef/audit/runner.rb +4 -2
- data/lib/chef/chef_class.rb +62 -11
- data/lib/chef/client.rb +587 -207
- data/lib/chef/config.rb +0 -1
- data/lib/chef/dsl/recipe.rb +45 -56
- data/lib/chef/dsl/resources.rb +3 -2
- data/lib/chef/event_dispatch/base.rb +7 -2
- data/lib/chef/exceptions.rb +4 -1
- data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
- data/lib/chef/formatters/doc.rb +15 -7
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
- data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
- data/lib/chef/http/authenticator.rb +7 -2
- data/lib/chef/knife.rb +16 -4
- data/lib/chef/knife/client_create.rb +55 -31
- data/lib/chef/knife/core/generic_presenter.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/osc_user_create.rb +97 -0
- data/lib/chef/knife/osc_user_delete.rb +51 -0
- data/lib/chef/knife/osc_user_edit.rb +58 -0
- data/lib/chef/knife/osc_user_list.rb +47 -0
- data/lib/chef/knife/osc_user_reregister.rb +64 -0
- data/lib/chef/knife/osc_user_show.rb +54 -0
- data/lib/chef/knife/user_create.rb +95 -36
- data/lib/chef/knife/user_delete.rb +52 -2
- data/lib/chef/knife/user_edit.rb +37 -7
- data/lib/chef/knife/user_list.rb +3 -0
- data/lib/chef/knife/user_reregister.rb +39 -8
- data/lib/chef/knife/user_show.rb +30 -1
- data/lib/chef/mixin/api_version_request_handling.rb +66 -0
- data/lib/chef/mixin/convert_to_class_name.rb +10 -4
- data/lib/chef/mixin/deprecation.rb +24 -0
- data/lib/chef/mixin/powershell_out.rb +98 -0
- data/lib/chef/mixin/provides.rb +5 -18
- data/lib/chef/mixin/uris.rb +11 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
- data/lib/chef/mixin/windows_env_helper.rb +11 -2
- data/lib/chef/node_map.rb +130 -75
- data/lib/chef/osc_user.rb +194 -0
- data/lib/chef/platform/provider_mapping.rb +2 -269
- data/lib/chef/platform/provider_priority_map.rb +6 -69
- data/lib/chef/platform/query_helpers.rb +5 -0
- data/lib/chef/platform/resource_priority_map.rb +12 -15
- data/lib/chef/policy_builder/policyfile.rb +1 -0
- data/lib/chef/provider.rb +19 -0
- data/lib/chef/provider/directory.rb +3 -0
- data/lib/chef/provider/dsc_resource.rb +8 -1
- data/lib/chef/provider/file.rb +1 -0
- data/lib/chef/provider/group/aix.rb +1 -0
- data/lib/chef/provider/group/dscl.rb +1 -1
- data/lib/chef/provider/group/gpasswd.rb +1 -0
- data/lib/chef/provider/group/groupmod.rb +1 -1
- data/lib/chef/provider/group/pw.rb +1 -0
- data/lib/chef/provider/group/suse.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +2 -1
- data/lib/chef/provider/group/windows.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -0
- data/lib/chef/provider/ifconfig/aix.rb +1 -0
- data/lib/chef/provider/ifconfig/debian.rb +2 -0
- data/lib/chef/provider/ifconfig/redhat.rb +1 -0
- data/lib/chef/provider/lwrp_base.rb +4 -0
- data/lib/chef/provider/mount.rb +0 -1
- data/lib/chef/provider/mount/aix.rb +1 -0
- data/lib/chef/provider/mount/mount.rb +2 -0
- data/lib/chef/provider/mount/solaris.rb +2 -0
- data/lib/chef/provider/package.rb +55 -0
- data/lib/chef/provider/package/aix.rb +7 -7
- data/lib/chef/provider/package/apt.rb +3 -3
- data/lib/chef/provider/package/dpkg.rb +4 -4
- data/lib/chef/provider/package/easy_install.rb +5 -5
- data/lib/chef/provider/package/freebsd/base.rb +2 -2
- data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
- data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
- data/lib/chef/provider/package/freebsd/port.rb +4 -4
- data/lib/chef/provider/package/homebrew.rb +2 -2
- data/lib/chef/provider/package/ips.rb +4 -4
- data/lib/chef/provider/package/macports.rb +5 -6
- data/lib/chef/provider/package/openbsd.rb +4 -5
- data/lib/chef/provider/package/pacman.rb +4 -4
- data/lib/chef/provider/package/portage.rb +2 -0
- data/lib/chef/provider/package/rpm.rb +7 -8
- data/lib/chef/provider/package/rubygems.rb +5 -12
- data/lib/chef/provider/package/smartos.rb +4 -4
- data/lib/chef/provider/package/solaris.rb +7 -7
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum.rb +4 -6
- data/lib/chef/provider/package/zypper.rb +16 -14
- data/lib/chef/provider/powershell_script.rb +129 -47
- data/lib/chef/provider/remote_file/content.rb +4 -1
- data/lib/chef/provider/remote_file/local_file.rb +10 -4
- data/lib/chef/provider/service.rb +44 -0
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/init.rb +1 -0
- data/lib/chef/provider/service/macosx.rb +1 -1
- data/lib/chef/provider/service/windows.rb +0 -1
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/aix.rb +3 -2
- data/lib/chef/provider/user/pw.rb +1 -0
- data/lib/chef/provider/user/solaris.rb +2 -0
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/provider_resolver.rb +87 -134
- data/lib/chef/resource.rb +274 -68
- data/lib/chef/resource/apt_package.rb +0 -2
- data/lib/chef/resource/bash.rb +0 -2
- data/lib/chef/resource/batch.rb +1 -1
- data/lib/chef/resource/bff_package.rb +0 -7
- data/lib/chef/resource/breakpoint.rb +3 -6
- data/lib/chef/resource/chef_gem.rb +0 -3
- data/lib/chef/resource/cookbook_file.rb +1 -3
- data/lib/chef/resource/cron.rb +2 -4
- data/lib/chef/resource/csh.rb +0 -2
- data/lib/chef/resource/deploy.rb +9 -6
- data/lib/chef/resource/deploy_revision.rb +0 -14
- data/lib/chef/resource/directory.rb +2 -4
- data/lib/chef/resource/dpkg_package.rb +0 -5
- data/lib/chef/resource/dsc_resource.rb +2 -3
- data/lib/chef/resource/dsc_script.rb +2 -3
- data/lib/chef/resource/easy_install_package.rb +0 -7
- data/lib/chef/resource/env.rb +3 -3
- data/lib/chef/resource/erl_call.rb +2 -5
- data/lib/chef/resource/execute.rb +2 -4
- data/lib/chef/resource/file.rb +2 -4
- data/lib/chef/resource/freebsd_package.rb +0 -5
- data/lib/chef/resource/gem_package.rb +0 -3
- data/lib/chef/resource/git.rb +0 -3
- data/lib/chef/resource/group.rb +2 -4
- data/lib/chef/resource/homebrew_package.rb +0 -2
- data/lib/chef/resource/http_request.rb +3 -4
- data/lib/chef/resource/ifconfig.rb +3 -4
- data/lib/chef/resource/ips_package.rb +2 -2
- data/lib/chef/resource/link.rb +3 -5
- data/lib/chef/resource/log.rb +2 -4
- data/lib/chef/resource/lwrp_base.rb +10 -61
- data/lib/chef/resource/macosx_service.rb +1 -2
- data/lib/chef/resource/macports_package.rb +0 -7
- data/lib/chef/resource/mdadm.rb +2 -5
- data/lib/chef/resource/mount.rb +2 -4
- data/lib/chef/resource/ohai.rb +2 -4
- data/lib/chef/resource/openbsd_package.rb +0 -6
- data/lib/chef/resource/package.rb +9 -6
- data/lib/chef/resource/pacman_package.rb +0 -7
- data/lib/chef/resource/paludis_package.rb +2 -3
- data/lib/chef/resource/perl.rb +0 -3
- data/lib/chef/resource/portage_package.rb +0 -3
- data/lib/chef/resource/powershell_script.rb +1 -2
- data/lib/chef/resource/python.rb +0 -3
- data/lib/chef/resource/reboot.rb +1 -3
- data/lib/chef/resource/registry_key.rb +3 -5
- data/lib/chef/resource/remote_directory.rb +3 -5
- data/lib/chef/resource/remote_file.rb +4 -5
- data/lib/chef/resource/route.rb +3 -5
- data/lib/chef/resource/rpm_package.rb +0 -2
- data/lib/chef/resource/ruby.rb +0 -4
- data/lib/chef/resource/ruby_block.rb +2 -4
- data/lib/chef/resource/scm.rb +3 -5
- data/lib/chef/resource/script.rb +0 -3
- data/lib/chef/resource/service.rb +3 -5
- data/lib/chef/resource/smartos_package.rb +0 -9
- data/lib/chef/resource/solaris_package.rb +0 -10
- data/lib/chef/resource/subversion.rb +1 -3
- data/lib/chef/resource/template.rb +0 -4
- data/lib/chef/resource/timestamped_deploy.rb +0 -4
- data/lib/chef/resource/user.rb +2 -5
- data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
- data/lib/chef/resource/windows_package.rb +3 -3
- data/lib/chef/resource/windows_script.rb +2 -2
- data/lib/chef/resource/windows_service.rb +3 -3
- data/lib/chef/resource/yum_package.rb +0 -3
- data/lib/chef/resource/zypper_package.rb +27 -0
- data/lib/chef/resource_builder.rb +7 -0
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resource_resolver.rb +108 -62
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/rest.rb +1 -0
- data/lib/chef/server_api.rb +2 -0
- data/lib/chef/user.rb +193 -42
- data/lib/chef/util/backup.rb +9 -1
- data/lib/chef/util/path_helper.rb +0 -1
- data/lib/chef/version.rb +1 -1
- data/spec/functional/audit/runner_spec.rb +22 -42
- data/spec/functional/mixin/powershell_out_spec.rb +43 -0
- data/spec/functional/resource/execute_spec.rb +9 -2
- data/spec/functional/resource/file_spec.rb +25 -0
- data/spec/functional/resource/group_spec.rb +5 -0
- data/spec/functional/resource/link_spec.rb +5 -11
- data/spec/functional/resource/powershell_spec.rb +40 -5
- data/spec/functional/resource/user/useradd_spec.rb +10 -18
- data/spec/integration/recipes/lwrp_spec.rb +57 -0
- data/spec/integration/recipes/provider_choice.rb +2 -7
- data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
- data/spec/spec_helper.rb +1 -1
- data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
- data/spec/support/lib/chef/resource/cat.rb +0 -2
- data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
- data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
- data/spec/support/lib/chef/resource/with_state.rb +0 -9
- data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
- data/spec/support/lib/chef/resource/zen_master.rb +1 -6
- data/spec/support/shared/context/client.rb +277 -0
- data/spec/support/shared/examples/client.rb +53 -0
- data/spec/support/shared/functional/file_resource.rb +0 -4
- data/spec/support/shared/functional/securable_resource.rb +0 -24
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
- data/spec/support/shared/functional/windows_script.rb +1 -1
- data/spec/support/shared/unit/api_versioning.rb +77 -0
- data/spec/support/shared/unit/knife_shared.rb +40 -0
- data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
- data/spec/unit/api_client_spec.rb +189 -14
- data/spec/unit/application/client_spec.rb +0 -5
- data/spec/unit/audit/audit_reporter_spec.rb +58 -14
- data/spec/unit/audit/logger_spec.rb +42 -0
- data/spec/unit/audit/runner_spec.rb +2 -2
- data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
- data/spec/unit/client_spec.rb +58 -374
- data/spec/unit/cookbook_spec.rb +0 -9
- data/spec/unit/cookbook_version_spec.rb +0 -20
- data/spec/unit/deprecation_spec.rb +55 -0
- data/spec/unit/dsl/resources_spec.rb +85 -0
- data/spec/unit/exceptions_spec.rb +2 -2
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
- data/spec/unit/formatters/doc_spec.rb +46 -0
- data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
- data/spec/unit/http/authenticator_spec.rb +11 -2
- data/spec/unit/knife/client_create_spec.rb +122 -51
- data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
- data/spec/unit/knife/core/ui_spec.rb +14 -0
- data/spec/unit/knife/osc_user_create_spec.rb +93 -0
- data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
- data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
- data/spec/unit/knife/osc_user_list_spec.rb +37 -0
- data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
- data/spec/unit/knife/osc_user_show_spec.rb +46 -0
- data/spec/unit/knife/user_create_spec.rb +177 -51
- data/spec/unit/knife/user_delete_spec.rb +34 -8
- data/spec/unit/knife/user_edit_spec.rb +31 -12
- data/spec/unit/knife/user_list_spec.rb +7 -3
- data/spec/unit/knife/user_reregister_spec.rb +38 -17
- data/spec/unit/knife/user_show_spec.rb +35 -11
- data/spec/unit/knife_spec.rb +10 -4
- data/spec/unit/lwrp_spec.rb +228 -54
- data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
- data/spec/unit/mixin/command_spec.rb +1 -2
- data/spec/unit/mixin/powershell_out_spec.rb +70 -0
- data/spec/unit/mixin/uris_spec.rb +23 -11
- data/spec/unit/node_map_spec.rb +4 -1
- data/spec/unit/osc_user_spec.rb +276 -0
- data/spec/unit/platform_spec.rb +0 -60
- data/spec/unit/provider/deploy_spec.rb +1 -1
- data/spec/unit/provider/directory_spec.rb +199 -135
- data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
- data/spec/unit/provider/package/aix_spec.rb +16 -16
- data/spec/unit/provider/package/dpkg_spec.rb +2 -2
- data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
- data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
- data/spec/unit/provider/package/ips_spec.rb +22 -22
- data/spec/unit/provider/package/macports_spec.rb +10 -10
- data/spec/unit/provider/package/openbsd_spec.rb +4 -26
- data/spec/unit/provider/package/pacman_spec.rb +5 -5
- data/spec/unit/provider/package/rpm_spec.rb +14 -14
- data/spec/unit/provider/package/rubygems_spec.rb +10 -44
- data/spec/unit/provider/package/smartos_spec.rb +4 -4
- data/spec/unit/provider/package/solaris_spec.rb +11 -11
- data/spec/unit/provider/package/zypper_spec.rb +125 -90
- data/spec/unit/provider/package_spec.rb +34 -0
- data/spec/unit/provider/powershell_spec.rb +53 -11
- data/spec/unit/provider/remote_directory_spec.rb +2 -2
- data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
- data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
- data/spec/unit/provider/user_spec.rb +3 -3
- data/spec/unit/provider_resolver_spec.rb +463 -327
- data/spec/unit/recipe_spec.rb +42 -15
- data/spec/unit/resource/breakpoint_spec.rb +1 -1
- data/spec/unit/resource/erl_call_spec.rb +1 -1
- data/spec/unit/resource/file_spec.rb +1 -1
- data/spec/unit/resource/ifconfig_spec.rb +10 -6
- data/spec/unit/resource/remote_file_spec.rb +5 -0
- data/spec/unit/resource/route_spec.rb +1 -1
- data/spec/unit/resource/ruby_block_spec.rb +2 -2
- data/spec/unit/resource/template_spec.rb +1 -1
- data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
- data/spec/unit/resource/windows_service_spec.rb +1 -1
- data/spec/unit/resource_spec.rb +99 -13
- data/spec/unit/rest_spec.rb +5 -5
- data/spec/unit/run_context_spec.rb +41 -0
- data/spec/unit/runner_spec.rb +2 -2
- data/spec/unit/user_spec.rb +406 -93
- data/tasks/maintainers.rb +69 -0
- metadata +37 -4
@@ -28,8 +28,8 @@ class Chef
|
|
28
28
|
class Service
|
29
29
|
class Macosx < Chef::Provider::Service::Simple
|
30
30
|
|
31
|
-
provides :service, os: "darwin"
|
32
31
|
provides :macosx_service, os: "darwin"
|
32
|
+
provides :service, os: "darwin"
|
33
33
|
|
34
34
|
def self.gather_plist_dirs
|
35
35
|
locations = %w{/Library/LaunchAgents
|
data/lib/chef/provider/user.rb
CHANGED
@@ -23,6 +23,7 @@ require 'etc'
|
|
23
23
|
class Chef
|
24
24
|
class Provider
|
25
25
|
class User < Chef::Provider
|
26
|
+
provides :user
|
26
27
|
|
27
28
|
include Chef::Mixin::Command
|
28
29
|
|
@@ -208,7 +209,6 @@ class Chef
|
|
208
209
|
def unlock_user
|
209
210
|
raise NotImplementedError
|
210
211
|
end
|
211
|
-
|
212
212
|
end
|
213
213
|
end
|
214
214
|
end
|
@@ -18,9 +18,10 @@ class Chef
|
|
18
18
|
class Provider
|
19
19
|
class User
|
20
20
|
class Aix < Chef::Provider::User::Useradd
|
21
|
+
provides :user, platform: %w(aix)
|
21
22
|
|
22
23
|
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]]
|
23
|
-
|
24
|
+
|
24
25
|
def create_user
|
25
26
|
super
|
26
27
|
add_password
|
@@ -88,7 +89,7 @@ class Chef
|
|
88
89
|
end
|
89
90
|
end
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
end
|
93
94
|
end
|
94
95
|
end
|
@@ -22,6 +22,8 @@ class Chef
|
|
22
22
|
class Provider
|
23
23
|
class User
|
24
24
|
class Solaris < Chef::Provider::User::Useradd
|
25
|
+
provides :user, platform: %w(omnios solaris2)
|
26
|
+
|
25
27
|
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:shell, "-s"], [:uid, "-u"]]
|
26
28
|
|
27
29
|
attr_writer :password_file
|
@@ -24,88 +24,25 @@ class Chef
|
|
24
24
|
# Provider Resolution
|
25
25
|
# ===================
|
26
26
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# the process of taking a Resource object and an action, and determining the
|
31
|
-
# Provider class that should be instantiated to handle the action.
|
27
|
+
# Provider resolution is the process of taking a Resource object and an
|
28
|
+
# action, and determining the Provider class that should be instantiated to
|
29
|
+
# handle the action.
|
32
30
|
#
|
33
|
-
# The process happens in three steps:
|
34
|
-
#
|
35
|
-
# Explicit Provider on the Resource
|
36
|
-
# ---------------------------------
|
37
31
|
# If the resource has its `provider` set, that is used.
|
38
32
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# can handle the action. It's a little more complicated than that, though:
|
44
|
-
#
|
45
|
-
# ### Provider.provides?
|
46
|
-
#
|
47
|
-
# First, we go through all known provider classes (all descendants of
|
48
|
-
# `Chef::Provider`), and call `provides?(node, resource)` to determine if it
|
49
|
-
# supports this action for this resource on this OS. We get a list of all
|
50
|
-
# matches.
|
51
|
-
#
|
52
|
-
# #### Defining provides
|
53
|
-
#
|
54
|
-
# The typical way of getting `provides?` is for the Provider class to call
|
55
|
-
# `provides :name`.
|
56
|
-
#
|
57
|
-
# The Provider may pass the OS, platform family, platform, and platform version
|
58
|
-
# to `provides`, and they will be matched against the values in the `node`
|
59
|
-
# object. The Provider may also pass a block, which allows for custom logic
|
60
|
-
# to decide whether it provides the resource or not.
|
61
|
-
#
|
62
|
-
# Some Providers also override `provides?` with custom logic.
|
63
|
-
#
|
64
|
-
# ### Provider.supports?
|
65
|
-
#
|
66
|
-
# Once we have the list of willing providers, we filter it by calling their
|
67
|
-
# `supports?(resource, action)` method to see if they support the specific
|
68
|
-
# action (`:create`, `:delete`) or not.
|
69
|
-
#
|
70
|
-
# If no provider supports the specific action, we fall back to the full list
|
71
|
-
# of matches from step 1. (TODO The comment says it's for why run. I'm not
|
72
|
-
# sure what that means specifically yet.)
|
73
|
-
#
|
74
|
-
# ### Priority lists: Chef.get_provider_priority_array
|
33
|
+
# Otherwise, we take the lists of Providers that have registered as
|
34
|
+
# providing the DSL through `provides :dsl_name, <filters>` or
|
35
|
+
# `Chef.set_resource_priority_array :dsl_name, <filters>`. We filter each
|
36
|
+
# list of Providers through:
|
75
37
|
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
38
|
+
# 1. The filters it was registered with (such as `os: 'linux'` or
|
39
|
+
# `platform_family: 'debian'`)
|
40
|
+
# 2. `provides?(node, resource)`
|
41
|
+
# 3. `supports?(resource, action)`
|
80
42
|
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
# alphabetically by class name.
|
85
|
-
#
|
86
|
-
# Chef::Platform Provider Map
|
87
|
-
# ---------------------------
|
88
|
-
# If we still have no matches, we try `Chef::Platform.find_provider_for_node(node, resource)`.
|
89
|
-
# This does two new things:
|
90
|
-
#
|
91
|
-
# ### System Provider Map
|
92
|
-
#
|
93
|
-
# The system provider map is a large Hash loaded during `require` time,
|
94
|
-
# which shows system-specific providers by os/platform, and platform_version.
|
95
|
-
# It keys off of `node[:platform] || node[:os]`, and `node[:platform_version]
|
96
|
-
# || node[:os_version] || node[:os_release]`. The version uses typical gem
|
97
|
-
# constraints like > and <=.
|
98
|
-
#
|
99
|
-
# The first platform+version match wins over the first platform-only match,
|
100
|
-
# which wins over the default.
|
101
|
-
#
|
102
|
-
# ### Chef::Provider::FooBar
|
103
|
-
#
|
104
|
-
# As a last resort, if there are *still* no classes, the system transforms the
|
105
|
-
# DSL name `foo_bar` into `Chef::Provider::FooBar`, and returns the class if
|
106
|
-
# it is there and descends from `Chef::Provider`.
|
107
|
-
#
|
108
|
-
# NOTE: this behavior is now deprecated.
|
43
|
+
# Anything that passes the filter and returns `true` to provides and supports,
|
44
|
+
# is considered a match. The first matching Provider in the *most recently
|
45
|
+
# registered list* is selected and returned.
|
109
46
|
#
|
110
47
|
class ProviderResolver
|
111
48
|
|
@@ -119,33 +56,14 @@ class Chef
|
|
119
56
|
@action = action
|
120
57
|
end
|
121
58
|
|
122
|
-
# return a deterministically sorted list of Chef::Provider subclasses
|
123
|
-
def providers
|
124
|
-
@providers ||= Chef::Provider.descendants
|
125
|
-
end
|
126
|
-
|
127
59
|
def resolve
|
128
60
|
maybe_explicit_provider(resource) ||
|
129
61
|
maybe_dynamic_provider_resolution(resource, action) ||
|
130
62
|
maybe_chef_platform_lookup(resource)
|
131
63
|
end
|
132
64
|
|
133
|
-
|
134
|
-
|
135
|
-
@enabled_handlers ||=
|
136
|
-
providers.select do |klass|
|
137
|
-
# NB: this is different from resource_resolver which must pass a resource_name
|
138
|
-
# FIXME: deprecate this and normalize on passing resource_name here
|
139
|
-
klass.provides?(node, resource)
|
140
|
-
end.sort {|a,b| a.to_s <=> b.to_s }
|
141
|
-
end
|
142
|
-
|
143
|
-
# this cut looks at if the provider can handle the specific resource and action
|
144
|
-
def supported_handlers
|
145
|
-
@supported_handlers ||=
|
146
|
-
enabled_handlers.select do |klass|
|
147
|
-
klass.supports?(resource, action)
|
148
|
-
end
|
65
|
+
def provided_by?(provider_class)
|
66
|
+
prioritized_handlers.include?(provider_class)
|
149
67
|
end
|
150
68
|
|
151
69
|
private
|
@@ -158,40 +76,37 @@ class Chef
|
|
158
76
|
|
159
77
|
# try dynamically finding a provider based on querying the providers to see what they support
|
160
78
|
def maybe_dynamic_provider_resolution(resource, action)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
#
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
handlers = [ handlers.first ]
|
79
|
+
Chef::Log.debug "Providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}"
|
80
|
+
|
81
|
+
# Get all the handlers in the priority bucket
|
82
|
+
handlers = prioritized_handlers
|
83
|
+
|
84
|
+
# Narrow it down to handlers that return `true` to `provides?`
|
85
|
+
# TODO deprecate this and don't bother calling--the fact that they said
|
86
|
+
# `provides` should be enough. But we need to do it right now because
|
87
|
+
# some classes implement additional handling.
|
88
|
+
enabled_handlers = prioritized_handlers.select { |handler| handler.provides?(node, resource) }
|
89
|
+
|
90
|
+
# Narrow it down to handlers that return `true` to `supports?`
|
91
|
+
# TODO deprecate this and allow actions to be passed as a filter to
|
92
|
+
# `provides` so we don't have to have two separate things.
|
93
|
+
supported_handlers = enabled_handlers.select { |handler| handler.supports?(resource, action) }
|
94
|
+
if supported_handlers.empty?
|
95
|
+
# if none of the providers specifically support the resource, we still need to pick one of the providers that are
|
96
|
+
# enabled on the node to handle the why-run use case. FIXME we should only do this in why-run mode then.
|
97
|
+
Chef::Log.debug "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway."
|
98
|
+
handler = enabled_handlers.first
|
99
|
+
else
|
100
|
+
handler = supported_handlers.first
|
184
101
|
end
|
185
102
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
return nil if handlers.empty?
|
103
|
+
if handler
|
104
|
+
Chef::Log.debug "Provider for action #{action} on resource #{resource} is #{handler}"
|
105
|
+
else
|
106
|
+
Chef::Log.debug "Dynamic provider resolver FAILED to resolve a provider for action #{action} on resource #{resource}"
|
107
|
+
end
|
193
108
|
|
194
|
-
|
109
|
+
handler
|
195
110
|
end
|
196
111
|
|
197
112
|
# try the old static lookup of providers by platform
|
@@ -199,13 +114,51 @@ class Chef
|
|
199
114
|
Chef::Platform.find_provider_for_node(node, resource)
|
200
115
|
end
|
201
116
|
|
202
|
-
# dep injection hooks
|
203
|
-
def get_priority_array(node, resource_name)
|
204
|
-
provider_priority_map.get_priority_array(node, resource_name)
|
205
|
-
end
|
206
|
-
|
207
117
|
def provider_priority_map
|
208
118
|
Chef::Platform::ProviderPriorityMap.instance
|
209
119
|
end
|
120
|
+
|
121
|
+
def prioritized_handlers
|
122
|
+
@prioritized_handlers ||=
|
123
|
+
provider_priority_map.list_handlers(node, resource.resource_name).flatten(1).uniq
|
124
|
+
end
|
125
|
+
|
126
|
+
module Deprecated
|
127
|
+
# return a deterministically sorted list of Chef::Provider subclasses
|
128
|
+
def providers
|
129
|
+
@providers ||= Chef::Provider.descendants
|
130
|
+
end
|
131
|
+
|
132
|
+
# this cut looks at if the provider can handle the resource type on the node
|
133
|
+
def enabled_handlers
|
134
|
+
@enabled_handlers ||=
|
135
|
+
providers.select do |klass|
|
136
|
+
# NB: this is different from resource_resolver which must pass a resource_name
|
137
|
+
# FIXME: deprecate this and normalize on passing resource_name here
|
138
|
+
klass.provides?(node, resource)
|
139
|
+
end.sort {|a,b| a.to_s <=> b.to_s }
|
140
|
+
end
|
141
|
+
|
142
|
+
# this cut looks at if the provider can handle the specific resource and action
|
143
|
+
def supported_handlers
|
144
|
+
@supported_handlers ||=
|
145
|
+
enabled_handlers.select do |klass|
|
146
|
+
klass.supports?(resource, action)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# If there are no providers for a DSL, we search through the
|
151
|
+
def prioritized_handlers
|
152
|
+
@prioritized_handlers ||= super || begin
|
153
|
+
result = providers.select { |handler| handler.provides?(node, resource) }.sort_by(:name)
|
154
|
+
if !result.empty?
|
155
|
+
Chef::Log.deprecation("#{resource.resource_name.to_sym} is marked as providing DSL #{method_symbol}, but provides #{resource.resource_name.to_sym.inspect} was never called!")
|
156
|
+
Chef::Log.deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
|
157
|
+
end
|
158
|
+
result
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
prepend Deprecated
|
210
163
|
end
|
211
164
|
end
|
data/lib/chef/resource.rb
CHANGED
@@ -34,9 +34,12 @@ require 'chef/platform'
|
|
34
34
|
require 'chef/resource/resource_notification'
|
35
35
|
require 'chef/provider_resolver'
|
36
36
|
require 'chef/resource_resolver'
|
37
|
+
require 'set'
|
37
38
|
|
38
39
|
require 'chef/mixin/deprecation'
|
39
40
|
require 'chef/mixin/provides'
|
41
|
+
require 'chef/mixin/shell_out'
|
42
|
+
require 'chef/mixin/powershell_out'
|
40
43
|
|
41
44
|
class Chef
|
42
45
|
class Resource
|
@@ -51,6 +54,12 @@ class Chef
|
|
51
54
|
include Chef::DSL::RebootPending
|
52
55
|
extend Chef::Mixin::Provides
|
53
56
|
|
57
|
+
# This lets user code do things like `not_if { shell_out!("command") }`
|
58
|
+
include Chef::Mixin::ShellOut
|
59
|
+
include Chef::Mixin::PowershellOut
|
60
|
+
|
61
|
+
NULL_ARG = Object.new
|
62
|
+
|
54
63
|
#
|
55
64
|
# The node the current Chef run is using.
|
56
65
|
#
|
@@ -82,7 +91,6 @@ class Chef
|
|
82
91
|
run_context.resource_collection.find(*args)
|
83
92
|
end
|
84
93
|
|
85
|
-
|
86
94
|
#
|
87
95
|
# Resource User Interface (for users)
|
88
96
|
#
|
@@ -101,8 +109,8 @@ class Chef
|
|
101
109
|
@before = nil
|
102
110
|
@params = Hash.new
|
103
111
|
@provider = nil
|
104
|
-
@allowed_actions =
|
105
|
-
@action =
|
112
|
+
@allowed_actions = self.class.allowed_actions.to_a
|
113
|
+
@action = self.class.default_action
|
106
114
|
@updated = false
|
107
115
|
@updated_by_last_action = false
|
108
116
|
@supports = {}
|
@@ -163,19 +171,24 @@ class Chef
|
|
163
171
|
# @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`)
|
164
172
|
# @return [Array[Symbol]] the list of actions.
|
165
173
|
#
|
174
|
+
attr_accessor :action
|
166
175
|
def action(arg=nil)
|
167
176
|
if arg
|
168
|
-
|
169
|
-
|
170
|
-
|
177
|
+
if arg.is_a?(Array)
|
178
|
+
arg = arg.map { |a| a.to_sym }
|
179
|
+
else
|
180
|
+
arg = arg.to_sym
|
181
|
+
end
|
182
|
+
Array(arg).each do |action|
|
171
183
|
validate(
|
172
184
|
{ action: action },
|
173
|
-
{ action: { kind_of: Symbol, equal_to:
|
185
|
+
{ action: { kind_of: Symbol, equal_to: allowed_actions } }
|
174
186
|
)
|
175
187
|
end
|
176
|
-
|
188
|
+
self.action = arg
|
177
189
|
else
|
178
|
-
|
190
|
+
# Pull the action from the class if it's not set
|
191
|
+
@action || self.class.default_action
|
179
192
|
end
|
180
193
|
end
|
181
194
|
|
@@ -183,8 +196,7 @@ class Chef
|
|
183
196
|
# Sets up a notification that will run a particular action on another resource
|
184
197
|
# if and when *this* resource is updated by an action.
|
185
198
|
#
|
186
|
-
# If the action does
|
187
|
-
# notification never triggers.)
|
199
|
+
# If the action does not update this resource, the notification never triggers.
|
188
200
|
#
|
189
201
|
# Only one resource may be specified per notification.
|
190
202
|
#
|
@@ -600,7 +612,7 @@ class Chef
|
|
600
612
|
#
|
601
613
|
|
602
614
|
def to_s
|
603
|
-
"#{
|
615
|
+
"#{resource_name}[#{name}]"
|
604
616
|
end
|
605
617
|
|
606
618
|
def to_text
|
@@ -761,6 +773,12 @@ class Chef
|
|
761
773
|
# have.
|
762
774
|
#
|
763
775
|
attr_accessor :allowed_actions
|
776
|
+
def allowed_actions(value=NULL_ARG)
|
777
|
+
if value != NULL_ARG
|
778
|
+
self.allowed_actions = value
|
779
|
+
end
|
780
|
+
@allowed_actions
|
781
|
+
end
|
764
782
|
|
765
783
|
#
|
766
784
|
# Whether or not this resource was updated during an action. If multiple
|
@@ -819,23 +837,15 @@ class Chef
|
|
819
837
|
end
|
820
838
|
|
821
839
|
#
|
822
|
-
# The
|
823
|
-
#
|
824
|
-
# @return [String] The DSL name of this resource.
|
825
|
-
def self.dsl_name
|
826
|
-
Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 11. Use resource.resource_name instead."
|
827
|
-
if name
|
828
|
-
name = self.name.split('::')[-1]
|
829
|
-
convert_to_snake_case(name)
|
830
|
-
end
|
831
|
-
end
|
832
|
-
|
840
|
+
# The display name of this resource type, for printing purposes.
|
833
841
|
#
|
834
|
-
#
|
842
|
+
# Will be used to print out the resource in messages, e.g. resource_name[name]
|
835
843
|
#
|
836
|
-
# @return [
|
844
|
+
# @return [Symbol] The name of this resource type (e.g. `:execute`).
|
837
845
|
#
|
838
|
-
|
846
|
+
def resource_name
|
847
|
+
@resource_name || self.class.resource_name
|
848
|
+
end
|
839
849
|
|
840
850
|
#
|
841
851
|
# Sets a list of capabilities of the real resource. For example, `:remount`
|
@@ -867,6 +877,66 @@ class Chef
|
|
867
877
|
nil
|
868
878
|
end
|
869
879
|
|
880
|
+
#
|
881
|
+
# The DSL name of this resource (e.g. `package` or `yum_package`)
|
882
|
+
#
|
883
|
+
# @return [String] The DSL name of this resource.
|
884
|
+
#
|
885
|
+
# @deprecated Use resource_name instead.
|
886
|
+
#
|
887
|
+
def self.dsl_name
|
888
|
+
Chef::Log.deprecation "Resource.dsl_name is deprecated and will be removed in Chef 13. Use resource_name instead."
|
889
|
+
if name
|
890
|
+
name = self.name.split('::')[-1]
|
891
|
+
convert_to_snake_case(name)
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
#
|
896
|
+
# The display name of this resource type, for printing purposes.
|
897
|
+
#
|
898
|
+
# This also automatically calls "provides" to provide DSL with the given
|
899
|
+
# name.
|
900
|
+
#
|
901
|
+
# resource_name defaults to your class name.
|
902
|
+
#
|
903
|
+
# Call `resource_name nil` to remove the resource name (and any
|
904
|
+
# corresponding DSL).
|
905
|
+
#
|
906
|
+
# @param value [Symbol] The desired name of this resource type (e.g.
|
907
|
+
# `execute`), or `nil` if this class is abstract and has no resource_name.
|
908
|
+
#
|
909
|
+
# @return [Symbol] The name of this resource type (e.g. `:execute`).
|
910
|
+
#
|
911
|
+
def self.resource_name(name=NULL_ARG)
|
912
|
+
# Setter
|
913
|
+
if name != NULL_ARG
|
914
|
+
remove_canonical_dsl
|
915
|
+
|
916
|
+
# Set the resource_name and call provides
|
917
|
+
if name
|
918
|
+
name = name.to_sym
|
919
|
+
# If our class is not already providing this name, provide it.
|
920
|
+
if !Chef::ResourceResolver.list(name).include?(self)
|
921
|
+
provides name, canonical: true
|
922
|
+
end
|
923
|
+
@resource_name = name
|
924
|
+
else
|
925
|
+
@resource_name = nil
|
926
|
+
end
|
927
|
+
else
|
928
|
+
# set resource_name automatically if it's not set
|
929
|
+
if !instance_variable_defined?(:@resource_name) && self.name
|
930
|
+
resource_name convert_to_snake_case(self.name.split('::')[-1])
|
931
|
+
end
|
932
|
+
end
|
933
|
+
|
934
|
+
@resource_name
|
935
|
+
end
|
936
|
+
def self.resource_name=(name)
|
937
|
+
resource_name(name)
|
938
|
+
end
|
939
|
+
|
870
940
|
#
|
871
941
|
# The module where Chef should look for providers for this resource.
|
872
942
|
# The provider for `MyResource` will be looked up using
|
@@ -881,11 +951,70 @@ class Chef
|
|
881
951
|
# # ...other stuff
|
882
952
|
# end
|
883
953
|
#
|
954
|
+
# @deprecated Use `provides` on the provider, or `provider` on the resource, instead.
|
955
|
+
#
|
884
956
|
def self.provider_base(arg=nil)
|
885
|
-
|
886
|
-
|
957
|
+
if arg
|
958
|
+
Chef::Log.deprecation("Resource.provider_base is deprecated and will be removed in Chef 13. Use provides on the provider, or provider on the resource, instead.")
|
959
|
+
end
|
960
|
+
@provider_base ||= arg || Chef::Provider
|
961
|
+
end
|
962
|
+
|
963
|
+
#
|
964
|
+
# The list of allowed actions for the resource.
|
965
|
+
#
|
966
|
+
# @param actions [Array<Symbol>] The list of actions to add to allowed_actions.
|
967
|
+
#
|
968
|
+
# @return [Arrau<Symbol>] The list of actions, as symbols.
|
969
|
+
#
|
970
|
+
def self.allowed_actions(*actions)
|
971
|
+
@allowed_actions ||=
|
972
|
+
if superclass.respond_to?(:allowed_actions)
|
973
|
+
superclass.allowed_actions.dup
|
974
|
+
else
|
975
|
+
[ :nothing ]
|
976
|
+
end
|
977
|
+
@allowed_actions |= actions
|
978
|
+
end
|
979
|
+
def self.allowed_actions=(value)
|
980
|
+
@allowed_actions = value
|
887
981
|
end
|
888
982
|
|
983
|
+
#
|
984
|
+
# The action that will be run if no other action is specified.
|
985
|
+
#
|
986
|
+
# Setting default_action will automatially add the action to
|
987
|
+
# allowed_actions, if it isn't already there.
|
988
|
+
#
|
989
|
+
# Defaults to :nothing.
|
990
|
+
#
|
991
|
+
# @param action_name [Symbol,Array<Symbol>] The default action (or series
|
992
|
+
# of actions) to use.
|
993
|
+
#
|
994
|
+
# @return [Symbol,Array<Symbol>] The default actions for the resource.
|
995
|
+
#
|
996
|
+
def self.default_action(action_name=NULL_ARG)
|
997
|
+
unless action_name.equal?(NULL_ARG)
|
998
|
+
if action_name.is_a?(Array)
|
999
|
+
@default_action = action_name.map { |arg| arg.to_sym }
|
1000
|
+
else
|
1001
|
+
@default_action = action_name.to_sym
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
self.allowed_actions |= Array(@default_action)
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
if @default_action
|
1008
|
+
@default_action
|
1009
|
+
elsif superclass.respond_to?(:default_action)
|
1010
|
+
superclass.default_action
|
1011
|
+
else
|
1012
|
+
:nothing
|
1013
|
+
end
|
1014
|
+
end
|
1015
|
+
def self.default_action=(action_name)
|
1016
|
+
default_action(action_name)
|
1017
|
+
end
|
889
1018
|
|
890
1019
|
#
|
891
1020
|
# Internal Resource Interface (for Chef)
|
@@ -961,10 +1090,31 @@ class Chef
|
|
961
1090
|
# NOTE: that we do not support unregistering classes as descendents like
|
962
1091
|
# we used to for LWRP unloading because that was horrible and removed in
|
963
1092
|
# Chef-12.
|
1093
|
+
# @deprecated
|
1094
|
+
# @api private
|
964
1095
|
alias :resource_classes :descendants
|
1096
|
+
# @deprecated
|
1097
|
+
# @api private
|
965
1098
|
alias :find_subclass_by_name :find_descendants_by_name
|
966
1099
|
end
|
967
1100
|
|
1101
|
+
# @deprecated
|
1102
|
+
# @api private
|
1103
|
+
# We memoize a sorted version of descendants so that resource lookups don't
|
1104
|
+
# have to sort all the things, all the time.
|
1105
|
+
# This was causing performance issues in test runs, and probably in real
|
1106
|
+
# life as well.
|
1107
|
+
@@sorted_descendants = nil
|
1108
|
+
def self.sorted_descendants
|
1109
|
+
@@sorted_descendants ||= descendants.sort_by { |x| x.to_s }
|
1110
|
+
end
|
1111
|
+
def self.inherited(child)
|
1112
|
+
super
|
1113
|
+
@sorted_descendants = nil
|
1114
|
+
child.resource_name
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
|
968
1118
|
# If an unknown method is invoked, determine whether the enclosing Provider's
|
969
1119
|
# lexical scope can fulfill the request. E.g. This happens when the Resource's
|
970
1120
|
# block invokes new_resource.
|
@@ -976,12 +1126,32 @@ class Chef
|
|
976
1126
|
end
|
977
1127
|
end
|
978
1128
|
|
979
|
-
|
980
|
-
|
1129
|
+
#
|
1130
|
+
# Mark this resource as providing particular DSL.
|
1131
|
+
#
|
1132
|
+
# Resources have an automatic DSL based on their resource_name, equivalent to
|
1133
|
+
# `provides :resource_name` (providing the resource on all OS's). If you
|
1134
|
+
# declare a `provides` with the given resource_name, it *replaces* that
|
1135
|
+
# provides (so that you can provide your resource DSL only on certain OS's).
|
1136
|
+
#
|
1137
|
+
def self.provides(name, **options, &block)
|
1138
|
+
name = name.to_sym
|
1139
|
+
|
1140
|
+
# `provides :resource_name, os: 'linux'`) needs to remove the old
|
1141
|
+
# canonical DSL before adding the new one.
|
1142
|
+
if @resource_name && name == @resource_name
|
1143
|
+
remove_canonical_dsl
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
result = Chef.set_resource_priority_array(name, self, options, &block)
|
981
1147
|
Chef::DSL::Resources.add_resource_dsl(name)
|
982
1148
|
result
|
983
1149
|
end
|
984
1150
|
|
1151
|
+
def self.provides?(node, resource)
|
1152
|
+
Chef::ResourceResolver.resolve(resource, node: node).provided_by?(self)
|
1153
|
+
end
|
1154
|
+
|
985
1155
|
# Helper for #notifies
|
986
1156
|
def validate_resource_spec!(resource_spec)
|
987
1157
|
run_context.resource_collection.validate_lookup_spec!(resource_spec)
|
@@ -1111,15 +1281,13 @@ class Chef
|
|
1111
1281
|
# === Returns
|
1112
1282
|
# <Chef::Resource>:: returns the proper Chef::Resource class
|
1113
1283
|
def self.resource_for_node(short_name, node)
|
1114
|
-
klass = Chef::ResourceResolver.
|
1284
|
+
klass = Chef::ResourceResolver.resolve(short_name, node: node)
|
1115
1285
|
raise Chef::Exceptions::NoSuchResourceType.new(short_name, node) if klass.nil?
|
1116
1286
|
klass
|
1117
1287
|
end
|
1118
1288
|
|
1119
1289
|
#
|
1120
|
-
# Returns the class
|
1121
|
-
# Only returns the *canonical* class with the given name, not the one that
|
1122
|
-
# would be picked by the ResourceResolver.
|
1290
|
+
# Returns the class with the given resource_name.
|
1123
1291
|
#
|
1124
1292
|
# ==== Parameters
|
1125
1293
|
# short_name<Symbol>:: short_name of the resource (ie :directory)
|
@@ -1127,49 +1295,73 @@ class Chef
|
|
1127
1295
|
# === Returns
|
1128
1296
|
# <Chef::Resource>:: returns the proper Chef::Resource class
|
1129
1297
|
#
|
1130
|
-
# @deprecated Chef::Resource::FooBar will no longer mean anything special in
|
1131
|
-
# Chef 13. Use `resource_for_node` instead.
|
1132
1298
|
def self.resource_matching_short_name(short_name)
|
1133
|
-
|
1134
|
-
rname = convert_to_class_name(short_name.to_s)
|
1135
|
-
result = Chef::Resource.const_get(rname)
|
1136
|
-
if result <= Chef::Resource
|
1137
|
-
Chef::Log.deprecation("Class Chef::Resource::#{rname} does not declare 'provides #{short_name.inspect}'.")
|
1138
|
-
Chef::Log.deprecation("This will no longer work in Chef 13: you must use 'provides' to provide DSL.")
|
1139
|
-
result
|
1140
|
-
end
|
1141
|
-
rescue NameError
|
1142
|
-
nil
|
1143
|
-
end
|
1299
|
+
Chef::ResourceResolver.resolve(short_name, canonical: true)
|
1144
1300
|
end
|
1145
1301
|
|
1146
|
-
#
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
Chef::Log.warn "#{class_name} already exists! Cannot create deprecation class for #{resource_class}"
|
1152
|
-
else
|
1153
|
-
deprecated_constants[class_name.to_sym] = resource_class
|
1154
|
-
end
|
1302
|
+
# @api private
|
1303
|
+
def self.register_deprecated_lwrp_class(resource_class, class_name)
|
1304
|
+
if Chef::Resource.const_defined?(class_name, false)
|
1305
|
+
Chef::Log.warn "#{class_name} already exists! Deprecation class overwrites #{resource_class}"
|
1306
|
+
Chef::Resource.send(:remove_const, class_name)
|
1155
1307
|
end
|
1156
1308
|
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1309
|
+
# In order to generate deprecation warnings when you use Chef::Resource::MyLwrp,
|
1310
|
+
# we make a special subclass (identical in nearly all respects) of the
|
1311
|
+
# actual LWRP. When you say any of these, a deprecation warning will be
|
1312
|
+
# generated:
|
1313
|
+
#
|
1314
|
+
# - Chef::Resource::MyLwrp.new(...)
|
1315
|
+
# - resource.is_a?(Chef::Resource::MyLwrp)
|
1316
|
+
# - resource.kind_of?(Chef::Resource::MyLwrp)
|
1317
|
+
# - case resource
|
1318
|
+
# when Chef::Resource::MyLwrp
|
1319
|
+
# end
|
1320
|
+
#
|
1321
|
+
resource_subclass = class_eval <<-EOM, __FILE__, __LINE__+1
|
1322
|
+
class Chef::Resource::#{class_name} < resource_class
|
1323
|
+
resource_name nil # we do not actually provide anything
|
1324
|
+
def initialize(*args, &block)
|
1325
|
+
Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
|
1326
|
+
super
|
1327
|
+
end
|
1328
|
+
def self.resource_name(*args)
|
1329
|
+
if args.empty?
|
1330
|
+
@resource_name ||= superclass.resource_name
|
1331
|
+
else
|
1332
|
+
super
|
1333
|
+
end
|
1334
|
+
end
|
1335
|
+
self
|
1336
|
+
end
|
1337
|
+
EOM
|
1338
|
+
# Make case, is_a and kind_of work with the new subclass, for backcompat.
|
1339
|
+
# Any subclass of Chef::Resource::ResourceClass is already a subclass of resource_class
|
1340
|
+
# Any subclass of resource_class is considered a subclass of Chef::Resource::ResourceClass
|
1341
|
+
resource_class.class_eval do
|
1342
|
+
define_method(:is_a?) do |other|
|
1343
|
+
other.is_a?(Module) && other === self
|
1344
|
+
end
|
1345
|
+
define_method(:kind_of?) do |other|
|
1346
|
+
other.is_a?(Module) && other === self
|
1163
1347
|
end
|
1164
1348
|
end
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1349
|
+
resource_subclass.class_eval do
|
1350
|
+
define_singleton_method(:===) do |other|
|
1351
|
+
Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
|
1352
|
+
# resource_subclass is a superclass of all resource_class descendants.
|
1353
|
+
if self == resource_subclass && other.class <= resource_class
|
1354
|
+
return true
|
1355
|
+
end
|
1356
|
+
super(other)
|
1357
|
+
end
|
1170
1358
|
end
|
1359
|
+
deprecated_constants[class_name.to_sym] = resource_subclass
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
def self.deprecated_constants
|
1363
|
+
@deprecated_constants ||= {}
|
1171
1364
|
end
|
1172
|
-
extend DeprecatedLWRPClass
|
1173
1365
|
|
1174
1366
|
# @api private
|
1175
1367
|
def lookup_provider_constant(name, action=:nothing)
|
@@ -1183,5 +1375,19 @@ class Chef
|
|
1183
1375
|
end
|
1184
1376
|
end
|
1185
1377
|
end
|
1378
|
+
|
1379
|
+
private
|
1380
|
+
|
1381
|
+
def self.remove_canonical_dsl
|
1382
|
+
if @resource_name
|
1383
|
+
remaining = Chef.resource_priority_map.delete_canonical(@resource_name, self)
|
1384
|
+
if !remaining
|
1385
|
+
Chef::DSL::Resources.remove_resource_dsl(@resource_name)
|
1386
|
+
end
|
1387
|
+
end
|
1388
|
+
end
|
1186
1389
|
end
|
1187
1390
|
end
|
1391
|
+
|
1392
|
+
# Requiring things at the bottom breaks cycles
|
1393
|
+
require 'chef/chef_class'
|