diff options
author | John Keiser <john@johnkeiser.com> | 2015-05-27 16:06:53 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-01 13:21:21 -0700 |
commit | 236570dc9605ac312b44508b1c3a6a0e7c19b4dc (patch) | |
tree | 966a79db0d03021e2ed0e5a9ba2bf5073fff153c /lib/chef/resource | |
parent | 02e8874637dd661b5aaf656a5c2d6fbbb5795619 (diff) | |
download | chef-236570dc9605ac312b44508b1c3a6a0e7c19b4dc.tar.gz |
Add default_action and allowed_actions to Resource class, remove from LWRP
Diffstat (limited to 'lib/chef/resource')
36 files changed, 90 insertions, 100 deletions
diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb index dca4fd04a6..0107b8968a 100644 --- a/lib/chef/resource/breakpoint.rb +++ b/lib/chef/resource/breakpoint.rb @@ -24,11 +24,12 @@ class Chef class Breakpoint < Chef::Resource use_automatic_resource_name + default_action :break + def initialize(action="break", *args) super(caller.first, *args) - @action = "break" - @allowed_actions << :break end + end end end diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb index ade9c0e3e3..08f4733497 100644 --- a/lib/chef/resource/cookbook_file.rb +++ b/lib/chef/resource/cookbook_file.rb @@ -29,10 +29,11 @@ class Chef use_automatic_resource_name + default_action :create + def initialize(name, run_context=nil) super @provider = Chef::Provider::CookbookFile - @action = "create" @source = ::File.basename(name) @cookbook = nil end diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index daf462866e..a399caebe9 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -29,10 +29,11 @@ class Chef use_automatic_resource_name + default_action :create + allowed_actions :create, :delete + def initialize(name, run_context=nil) super - @action = :create - @allowed_actions.push(:create, :delete) @minute = "*" @hour = "*" @day = "*" diff --git a/lib/chef/resource/deploy.rb b/lib/chef/resource/deploy.rb index 8d007df348..f88133119a 100644 --- a/lib/chef/resource/deploy.rb +++ b/lib/chef/resource/deploy.rb @@ -56,6 +56,9 @@ class Chef state_attrs :deploy_to, :revision + default_action :deploy + allowed_actions :force_deploy, :deploy, :rollback + def initialize(name, run_context=nil) super @deploy_to = name @@ -67,7 +70,6 @@ class Chef @symlink_before_migrate = {"config/database.yml" => "config/database.yml"} @symlinks = {"system" => "public/system", "pids" => "tmp/pids", "log" => "log"} @revision = 'HEAD' - @action = :deploy @migrate = false @rollback_on_error = false @remote = "origin" @@ -75,7 +77,6 @@ class Chef @shallow_clone = false @scm_provider = Chef::Provider::Git @svn_force_export = false - @allowed_actions.push(:force_deploy, :deploy, :rollback) @additional_remotes = Hash[] @keep_releases = 5 @enable_checkout = true diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb index ea1805353d..304317e07a 100644 --- a/lib/chef/resource/directory.rb +++ b/lib/chef/resource/directory.rb @@ -34,12 +34,13 @@ class Chef use_automatic_resource_name + default_action :create + allowed_actions :create, :delete + def initialize(name, run_context=nil) super @path = name - @action = :create @recursive = false - @allowed_actions.push(:create, :delete) end def recursive(arg=nil) diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index cdfdff54f0..7c822604e2 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -26,12 +26,12 @@ class Chef include Chef::DSL::Powershell
+ default_action :run
+
def initialize(name, run_context)
super
@properties = {}
@resource = nil
- @allowed_actions.push(:run)
- @action = :run
end
def resource(value=nil)
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb index 4eabb92438..0ff7988d7d 100644 --- a/lib/chef/resource/dsc_script.rb +++ b/lib/chef/resource/dsc_script.rb @@ -25,10 +25,10 @@ class Chef use_automatic_resource_name provides :dsc_script, platform: "windows" + default_action :run + def initialize(name, run_context=nil) super - @allowed_actions.push(:run) - @action = :run @imports = {} end diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb index d74b4feee0..da7d48f062 100644 --- a/lib/chef/resource/env.rb +++ b/lib/chef/resource/env.rb @@ -28,13 +28,14 @@ class Chef use_automatic_resource_name provides :env, os: "windows" + default_action :create + allowed_actions :create, :delete, :modify + def initialize(name, run_context=nil) super @key_name = name @value = nil - @action = :create @delim = nil - @allowed_actions.push(:create, :delete, :modify) end def key_name(arg=nil) diff --git a/lib/chef/resource/erl_call.rb b/lib/chef/resource/erl_call.rb index c6d45c7aca..b025259b4c 100644 --- a/lib/chef/resource/erl_call.rb +++ b/lib/chef/resource/erl_call.rb @@ -29,6 +29,8 @@ class Chef identity_attr :code + default_action :run + def initialize(name, run_context=nil) super @@ -37,9 +39,6 @@ class Chef @distributed = false # if you want to have a distributed erlang node @name_type = "sname" # type of erlang hostname name or sname @node_name = "chef@localhost" # the erlang node hostname - - @action = "run" - @allowed_actions.push(:run) end def code(arg=nil) diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb index c0263501c5..34ed6b1bd9 100644 --- a/lib/chef/resource/execute.rb +++ b/lib/chef/resource/execute.rb @@ -33,11 +33,12 @@ class Chef # Only execute resources (and subclasses) can be guard interpreters. attr_accessor :is_guard_interpreter + default_action :run + def initialize(name, run_context=nil) super @command = name @backup = 5 - @action = "run" @creates = nil @cwd = nil @environment = nil @@ -46,7 +47,6 @@ class Chef @returns = 0 @timeout = nil @user = nil - @allowed_actions.push(:run) @umask = nil @default_guard_interpreter = :execute @is_guard_interpreter = false diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb index 32fd984f8c..51969f65a0 100644 --- a/lib/chef/resource/file.rb +++ b/lib/chef/resource/file.rb @@ -48,13 +48,13 @@ class Chef attr_accessor :final_checksum use_automatic_resource_name + default_action :create + allowed_actions :create, :delete, :touch, :create_if_missing def initialize(name, run_context=nil) super @path = name @backup = 5 - @action = "create" - @allowed_actions.push(:create, :delete, :touch, :create_if_missing) @atomic_update = Chef::Config[:file_atomic_update] @force_unlink = false @manage_symlink_source = nil diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb index 64062dbe8f..49cf92a282 100644 --- a/lib/chef/resource/group.rb +++ b/lib/chef/resource/group.rb @@ -27,16 +27,17 @@ class Chef use_automatic_resource_name + allowed_actions :create, :remove, :modify, :manage + default_action :create + def initialize(name, run_context=nil) super @group_name = name @gid = nil @members = [] @excluded_members = [] - @action = :create @append = false @non_unique = false - @allowed_actions.push(:create, :remove, :modify, :manage) end def group_name(arg=nil) diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb index ea22a26456..192484f557 100644 --- a/lib/chef/resource/http_request.rb +++ b/lib/chef/resource/http_request.rb @@ -27,13 +27,14 @@ class Chef identity_attr :url + default_action :get + allowed_actions :get, :put, :post, :delete, :head, :options + def initialize(name, run_context=nil) super @message = name @url = nil - @action = :get @headers = {} - @allowed_actions.push(:get, :put, :post, :delete, :head, :options) end def url(args=nil) diff --git a/lib/chef/resource/ifconfig.rb b/lib/chef/resource/ifconfig.rb index 18a688c2a5..47adc52425 100644 --- a/lib/chef/resource/ifconfig.rb +++ b/lib/chef/resource/ifconfig.rb @@ -28,11 +28,12 @@ class Chef state_attrs :inet_addr, :mask + default_action :add + allowed_actions :add, :delete, :enable, :disable + def initialize(name, run_context=nil) super @target = name - @action = :add - @allowed_actions.push(:add, :delete, :enable, :disable) @hwaddr = nil @mask = nil @inet_addr = nil diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb index 93b554eb6c..6b40fe138c 100644 --- a/lib/chef/resource/ips_package.rb +++ b/lib/chef/resource/ips_package.rb @@ -26,9 +26,10 @@ class Chef use_automatic_resource_name provides :ips_package, os: "solaris2" + allowed_actions :install, :remove, :upgrade + def initialize(name, run_context = nil) super(name, run_context) - @allowed_actions.push(:install, :remove, :upgrade) @accept_license = false end diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index 84a2b94ca1..2fe4da718c 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -31,14 +31,15 @@ class Chef state_attrs :to, :owner, :group + default_action :create + allowed_actions :create, :delete + def initialize(name, run_context=nil) verify_links_supported! super @to = nil - @action = :create @link_type = :symbolic @target_file = name - @allowed_actions.push(:create, :delete) end def to(arg=nil) diff --git a/lib/chef/resource/log.rb b/lib/chef/resource/log.rb index 5b4081b0fe..5c119df4d8 100644 --- a/lib/chef/resource/log.rb +++ b/lib/chef/resource/log.rb @@ -27,6 +27,8 @@ class Chef identity_attr :message + default_action :write + # Sends a string from a recipe to a log provider # # log "some string to log" do @@ -50,8 +52,6 @@ class Chef def initialize(name, run_context=nil) super @level = :info - @action = :write - @allowed_actions.push(:write) @message = name end diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index 129fc38d6f..20d236a161 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -82,42 +82,21 @@ class Chef end end - # Sets the default action - def default_action(action_name=NULL_ARG) - unless action_name.equal?(NULL_ARG) - @actions ||= [] - if action_name.is_a?(Array) - action = action_name.map { |arg| arg.to_sym } - @actions = actions | action - @default_action = action - else - action = action_name.to_sym - @actions.push(action) unless @actions.include?(action) - @default_action = [action] - end - end - - @default_action ||= from_superclass(:default_action) - end - # Adds +action_names+ to the list of valid actions for this resource. + # Does not include superclass's action list when appending. def actions(*action_names) - if action_names.empty? - defined?(@actions) ? @actions : from_superclass(:actions, []).dup + if !action_names.empty? && !@allowed_actions + self.allowed_actions = action_names else - # BC-compat way for checking if actions have already been defined - if defined?(@actions) - @actions.push(*action_names) - else - @actions = action_names - end + allowed_actions(*action_names) end end + alias :actions= :allowed_actions= # @deprecated def valid_actions(*args) - Chef::Log.warn("`valid_actions' is deprecated, please use actions `instead'!") - actions(*args) + Chef::Log.warn("`valid_actions' is deprecated, please use allowed_actions `instead'!") + allowed_actions(*args) end # Set the run context on the class. Used to provide access to the node @@ -149,15 +128,6 @@ class Chef superclass.respond_to?(m) ? superclass.send(m) : default end end - - private - - # Default initializer. Sets the default action and allowed actions. - def initialize(*args, &block) - super - @action = self.class.default_action - allowed_actions.push(self.class.actions).flatten! - end end end end diff --git a/lib/chef/resource/mdadm.rb b/lib/chef/resource/mdadm.rb index 8f19410b9c..2927cc8321 100644 --- a/lib/chef/resource/mdadm.rb +++ b/lib/chef/resource/mdadm.rb @@ -29,6 +29,9 @@ class Chef use_automatic_resource_name + default_action :create + allowed_actions :create, :assemble, :stop + def initialize(name, run_context=nil) super @@ -39,9 +42,6 @@ class Chef @metadata = "0.90" @bitmap = nil @raid_device = name - - @action = :create - @allowed_actions.push(:create, :assemble, :stop) end def chunk(arg=nil) diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb index f8a0cd157b..ce6d2cc232 100644 --- a/lib/chef/resource/mount.rb +++ b/lib/chef/resource/mount.rb @@ -29,6 +29,9 @@ class Chef use_automatic_resource_name + default_action :mount + allowed_actions :mount, :umount, :remount, :enable, :disable + def initialize(name, run_context=nil) super @mount_point = name @@ -41,9 +44,7 @@ class Chef @pass = 2 @mounted = false @enabled = false - @action = :mount @supports = { :remount => false } - @allowed_actions.push(:mount, :umount, :remount, :enable, :disable) @username = nil @password = nil @domain = nil diff --git a/lib/chef/resource/ohai.rb b/lib/chef/resource/ohai.rb index be24e97bde..005b149442 100644 --- a/lib/chef/resource/ohai.rb +++ b/lib/chef/resource/ohai.rb @@ -26,11 +26,11 @@ class Chef state_attrs :plugin + default_action :reload + def initialize(name, run_context=nil) super @name = name - @allowed_actions.push(:reload) - @action = :reload @plugin = nil end diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb index 0f4a5359ae..4148144816 100644 --- a/lib/chef/resource/package.rb +++ b/lib/chef/resource/package.rb @@ -28,10 +28,11 @@ class Chef state_attrs :version, :options + default_action :install + allowed_actions :install, :upgrade, :remove, :purge, :reconfig + def initialize(name, run_context=nil) super - @action = :install - @allowed_actions.push(:install, :upgrade, :remove, :purge, :reconfig) @candidate_version = nil @options = nil @package_name = name diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb index 0907ba71a9..f0ddc5927a 100644 --- a/lib/chef/resource/paludis_package.rb +++ b/lib/chef/resource/paludis_package.rb @@ -26,9 +26,10 @@ class Chef use_automatic_resource_name provides :paludis_package, os: "linux" + allowed_actions :install, :remove, :upgrade + def initialize(name, run_context=nil) super(name, run_context) - @allowed_actions.push(:install, :remove, :upgrade) @timeout = 3600 end end diff --git a/lib/chef/resource/reboot.rb b/lib/chef/resource/reboot.rb index c2a4ff29e2..216367692f 100644 --- a/lib/chef/resource/reboot.rb +++ b/lib/chef/resource/reboot.rb @@ -26,10 +26,11 @@ class Chef class Reboot < Chef::Resource use_automatic_resource_name + allowed_actions :request_reboot, :reboot_now, :cancel + def initialize(name, run_context=nil) super @provider = Chef::Provider::Reboot - @allowed_actions.push(:request_reboot, :reboot_now, :cancel) @reason = "Reboot by Chef" @delay_mins = 0 diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index 5a700e5365..9ee031b751 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -27,6 +27,9 @@ class Chef identity_attr :key state_attrs :values + default_action :create + allowed_actions :create, :create_if_missing, :delete, :delete_key + # Some registry key data types may not be safely reported as json. # Example (CHEF-5323): # @@ -60,12 +63,10 @@ class Chef def initialize(name, run_context=nil) super - @action = :create @architecture = :machine @recursive = false @key = name @values, @unscrubbed_values = [], [] - @allowed_actions.push(:create, :create_if_missing, :delete, :delete_key) end def key(arg=nil) diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index a35e0995b0..bb052d3bd4 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -32,12 +32,14 @@ class Chef state_attrs :files_owner, :files_group, :files_mode + default_action :create + allowed_actions :create, :create_if_missing, :delete + def initialize(name, run_context=nil) super @path = name @source = ::File.basename(name) @delete = false - @action = :create @recursive = true @purge = false @files_backup = 5 @@ -45,7 +47,6 @@ class Chef @files_group = nil @files_mode = 0644 unless Chef::Platform.windows? @overwrite = true - @allowed_actions.push(:create, :create_if_missing, :delete) @cookbook = nil end diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index 603151357c..99c21cae52 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -32,7 +32,6 @@ class Chef def initialize(name, run_context=nil) super - @action = "create" @source = [] @use_etag = true @use_last_modified = true diff --git a/lib/chef/resource/route.rb b/lib/chef/resource/route.rb index aca2a52e87..3df767a128 100644 --- a/lib/chef/resource/route.rb +++ b/lib/chef/resource/route.rb @@ -28,11 +28,12 @@ class Chef state_attrs :netmask, :gateway + default_action :add + allowed_actions :add, :delete + def initialize(name, run_context=nil) super @target = name - @action = [:add] - @allowed_actions.push(:add, :delete) @netmask = nil @gateway = nil @metric = nil diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb index e4667533f2..4ce7b2cee1 100644 --- a/lib/chef/resource/ruby_block.rb +++ b/lib/chef/resource/ruby_block.rb @@ -24,13 +24,13 @@ class Chef class Resource class RubyBlock < Chef::Resource use_automatic_resource_name + default_action :run + allowed_actions :create, :run identity_attr :block_name def initialize(name, run_context=nil) super - @action = "run" - @allowed_actions << :create << :run @block_name = name end diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb index c97090d0a5..8379a3d8a9 100644 --- a/lib/chef/resource/scm.rb +++ b/lib/chef/resource/scm.rb @@ -28,6 +28,9 @@ class Chef state_attrs :revision + default_action :sync + allowed_actions :checkout, :export, :sync, :diff, :log + def initialize(name, run_context=nil) super @destination = name @@ -37,8 +40,6 @@ class Chef @remote = "origin" @ssh_wrapper = nil @depth = nil - @allowed_actions.push(:checkout, :export, :sync, :diff, :log) - @action = [:sync] @checkout_branch = "deploy" @environment = nil end diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 6ef203db3b..9995eccb3f 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -28,6 +28,9 @@ class Chef state_attrs :enabled, :running + default_action :nothing + allowed_actions :enable, :disable, :start, :stop, :restart, :reload + def initialize(name, run_context=nil) super @service_name = name @@ -43,9 +46,7 @@ class Chef @init_command = nil @priority = nil @timeout = nil - @action = "nothing" @supports = { :restart => false, :reload => false, :status => false } - @allowed_actions.push(:enable, :disable, :start, :stop, :restart, :reload) end def service_name(arg=nil) diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb index f1b0391a8c..e12d939ca6 100644 --- a/lib/chef/resource/subversion.rb +++ b/lib/chef/resource/subversion.rb @@ -23,12 +23,12 @@ class Chef class Resource class Subversion < Chef::Resource::Scm use_automatic_resource_name + allowed_actions :force_export def initialize(name, run_context=nil) super @svn_arguments = '--no-auth-cache' @svn_info_args = '--no-auth-cache' - allowed_actions << :force_export end # Override exception to strip password if any, so it won't appear in logs and different Chef notifications diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb index 2c7ade6c29..a8e38aa5fb 100644 --- a/lib/chef/resource/template.rb +++ b/lib/chef/resource/template.rb @@ -34,7 +34,6 @@ class Chef def initialize(name, run_context=nil) super - @action = "create" @source = "#{::File.basename(name)}.erb" @cookbook = nil @local = false diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb index b762001d4b..66c183ad7e 100644 --- a/lib/chef/resource/user.rb +++ b/lib/chef/resource/user.rb @@ -28,6 +28,9 @@ class Chef use_automatic_resource_name + default_action :create + allowed_actions :create, :remove, :modify, :manage, :lock, :unlock + def initialize(name, run_context=nil) super @username = name @@ -41,14 +44,12 @@ class Chef @manage_home = false @force = false @non_unique = false - @action = :create @supports = { :manage_home => false, :non_unique => false } @iterations = 27855 @salt = nil - @allowed_actions.push(:create, :remove, :modify, :manage, :lock, :unlock) end def username(arg=nil) diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb index 8f9944a5af..bcf288e7b2 100644 --- a/lib/chef/resource/windows_package.rb +++ b/lib/chef/resource/windows_package.rb @@ -30,9 +30,10 @@ class Chef provides :windows_package, os: "windows" provides :package, os: "windows" + allowed_actions :install, :remove + def initialize(name, run_context=nil) super - @allowed_actions.push(:install, :remove) @source ||= source(@package_name) # Unique to this resource diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 3f62a67a82..099042840c 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -29,13 +29,14 @@ class Chef provides :windows_service, os: "windows" provides :service, os: "windows" + allowed_actions :configure_startup + identity_attr :service_name state_attrs :enabled, :running def initialize(name, run_context=nil) super - @allowed_actions.push(:configure_startup) @startup_type = :automatic @run_as_user = "" @run_as_password = "" |