Class | Chef::Resource

In:

lib/chef/resource/cron.rb
lib/chef/resource/user.rb
lib/chef/resource/ips_package.rb
lib/chef/resource/service.rb
lib/chef/resource/mdadm.rb
lib/chef/resource/ruby_block.rb
lib/chef/resource/rpm_package.rb
lib/chef/resource/group.rb
lib/chef/resource/git.rb
lib/chef/resource/subversion.rb
lib/chef/resource/timestamped_deploy.rb
lib/chef/resource/scm.rb
lib/chef/resource/apt_package.rb
lib/chef/resource/file.rb
lib/chef/resource/deploy.rb
lib/chef/resource/perl.rb
lib/chef/resource/freebsd_package.rb
lib/chef/resource/ifconfig.rb
lib/chef/resource/solaris_package.rb
lib/chef/resource/route.rb
lib/chef/resource/pacman_package.rb
lib/chef/resource/bash.rb
lib/chef/resource/link.rb
lib/chef/resource/macports_package.rb
lib/chef/resource/breakpoint.rb
lib/chef/resource/easy_install_package.rb
lib/chef/resource/remote_file.rb
lib/chef/resource/gem_package.rb
lib/chef/resource/erl_call.rb
lib/chef/resource/execute.rb
lib/chef/resource/python.rb
lib/chef/resource/template.rb
lib/chef/resource/conditional.rb
lib/chef/resource/env.rb
lib/chef/resource/dpkg_package.rb
lib/chef/resource/directory.rb
lib/chef/resource/smartos_package.rb
lib/chef/resource/cookbook_file.rb
lib/chef/resource/csh.rb
lib/chef/resource/http_request.rb
lib/chef/resource/script.rb
lib/chef/resource/portage_package.rb
lib/chef/resource/yum_package.rb
lib/chef/resource/mount.rb
lib/chef/resource/ohai.rb
lib/chef/resource/deploy_revision.rb
lib/chef/resource/remote_directory.rb
lib/chef/resource/package.rb
lib/chef/resource/chef_gem.rb
lib/chef/resource/ruby.rb
lib/chef/resource/log.rb
lib/chef/resource_platform_map.rb
lib/chef/resource.rb

Parent: | Object

### Methods

action add_notification after_created as_json attribute build_from_file cookbook_version customize_exception defined_at delayed_notifications dsl_name epic_fail events find_subclass_by_name identity identity_attr ignore_failure immediate_notifications inherited inspect is json_create load_prior_resource method_missing name new new node noop not_if notifies notifies_delayed notifies_immediately only_if platform_map provider provider_base provider_for_action provides resolve_notification_references resource_classes resource_for_node resource_for_platform resources retries retry_delay run_action should_skip? state state_attrs subscribes supports to_hash to_json to_s to_text updated= updated? updated_by_last_action updated_by_last_action? validate_action

### Included Modules

Chef::Mixin::CheckHelper Chef::Mixin::ParamsValidate Chef::Mixin::Language Chef::Mixin::ConvertToClassName Chef::Mixin::Deprecation

### Classes and Modules

Class Chef::Resource::AptPackage
Class Chef::Resource::Bash
Class Chef::Resource::Breakpoint
Class Chef::Resource::ChefGem
Class Chef::Resource::Conditional
Class Chef::Resource::CookbookFile
Class Chef::Resource::Cron
Class Chef::Resource::Csh
Class Chef::Resource::Deploy
Class Chef::Resource::DeployBranch
Class Chef::Resource::DeployRevision
Class Chef::Resource::Directory
Class Chef::Resource::DpkgPackage
Class Chef::Resource::EasyInstallPackage
Class Chef::Resource::Env
Class Chef::Resource::ErlCall
Class Chef::Resource::Execute
Class Chef::Resource::File
Class Chef::Resource::FreebsdPackage
Class Chef::Resource::GemPackage
Class Chef::Resource::Git
Class Chef::Resource::Group
Class Chef::Resource::HttpRequest
Class Chef::Resource::Ifconfig
Class Chef::Resource::IpsPackage
Class Chef::Resource::Link
Class Chef::Resource::Log
Class Chef::Resource::MacportsPackage
Class Chef::Resource::Mdadm
Class Chef::Resource::Mount
Class Chef::Resource::Notification
Class Chef::Resource::Ohai
Class Chef::Resource::Package
Class Chef::Resource::PacmanPackage
Class Chef::Resource::Perl
Class Chef::Resource::PlatformMap
Class Chef::Resource::PortagePackage
Class Chef::Resource::Python
Class Chef::Resource::RemoteDirectory
Class Chef::Resource::RemoteFile
Class Chef::Resource::Route
Class Chef::Resource::RpmPackage
Class Chef::Resource::Ruby
Class Chef::Resource::RubyBlock
Class Chef::Resource::Scm
Class Chef::Resource::Script
Class Chef::Resource::Service
Class Chef::Resource::SmartOSPackage
Class Chef::Resource::SolarisPackage
Class Chef::Resource::Subversion
Class Chef::Resource::Template
Class Chef::Resource::TimestampedDeploy
Class Chef::Resource::User
Class Chef::Resource::YumPackage

### Constants

FORBIDDEN_IVARS | = | [:@run_context, :@node, :@not_if, :@only_if, :@enclosing_provider]
HIDDEN_IVARS | = | [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@node, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider]

### Attributes

allowed_actions | [RW] |
cookbook_name | [RW] |
elapsed_time | [R] |
enclosing_provider | [RW] |
not_if_args | [R] |
only_if_args | [R] |
params | [RW] |
provider | [RW] |
recipe_name | [RW] |
resource_name | [R] |
retries | [RW] |
retry_delay | [RW] |
run_context | [RW] |
source_line | [RW] |
updated | [R] |

### Public Class methods

attribute(attr_name, validation_opts={})
build_from_file(cookbook_name, filename, run_context)
dsl_name()
find_subclass_by_name(class_name)

Look up a subclass by `class_name` which should be a string that matches `Subclass.name`

identity_attr(attr_name=nil)

Set or return the "identity attribute" for this resource class. This is generally going to be the "name attribute" for this resource. In other words, the resource type plus this attribute uniquely identify a given bit of state that chef manages. For a File resource, this would be the path, for a package resource, it will be the package name. This will show up in chef-client‘s audit records as a searchable field.

inherited(subclass)

Callback when subclass is defined. Adds subclass to list of subclasses.

json_create(o)
new(name, run_context=nil)

Each notify entry is a resource/action pair, modeled as an Struct with a resource and action member

new(name, run_context)

default initialize method that ensures that when initialize is finally wrapped (see below), super is called in the event that the resource definer does not implement initialize

platform_map()
provider_base(arg=nil)

Resources that want providers namespaced somewhere other than Chef::Provider can set the namespace with `provider_base` Ex:

      class MyResource < Chef::Resource
        provider_base Chef::Provider::Deploy
        # ...other stuff
      end

provides(short_name, opts={})

Maps a short_name (and optionally a platform and version) to a Chef::Resource. This allows finer grained per platform resource attributes and the end of overloaded resource definitions (I‘m looking at you Chef::Resource::Package) Ex:

      class WindowsFile < Chef::Resource
        provides :file, :on_platforms => ["windows"]
        # ...other stuff
      end

TODO: 2011-11-02 schisamo - platform_version support

resource_classes()

Track all subclasses of Resource. This is used so names can be looked up when attempting to deserialize from JSON. (See: json_compat)

resource_for_node(short_name, node)

Returns a resource based on a short_name and a node‘s platform and version.

#### Parameters

short_name<Symbol>: | short_name of the resource (ie :directory)
node<Chef::Node>: | Node object to look up platform and version in

### Returns

<Chef::Resource>: | returns the proper Chef::Resource class

resource_for_platform(short_name, platform=nil, version=nil)

Returns a resource based on a short_name anda platform and version.

#### Parameters

short_name<Symbol>: | short_name of the resource (ie :directory)
platform<Symbol,String>: | platform name
version<String>: | platform version

### Returns

<Chef::Resource>: | returns the proper Chef::Resource class

state_attrs(*attr_names)

Set or return the list of "state attributes" implemented by the Resource subclass. State attributes are attributes that describe the desired state of the system, such as file permissions or ownership. In general, state attributes are attributes that could be populated by examining the state of the system (e.g., File.stat can tell you the permissions on an existing file). Contrarily, attributes that are not "state attributes" usually modify the way Chef itself behaves, for example by providing additional options for a package manager to use when installing a package.

This list is used by the Chef client auditing system to extract information from resources to describe changes made to the system.

### Public Instance methods

action(arg=nil)
add_notification(action, resources, timing=:delayed)
after_created()

Hook to allow a resource to run specific code after creation

as_json(*a)

as_json does most of the to_json heavy lifted. It exists here in case activesupport is loaded. activesupport will call as_json and skip over to_json. This ensure json is encoded as expected

cookbook_version()
customize_exception(e)
defined_at()
delayed_notifications()
epic_fail(arg=nil)
events()
identity()

Returns the value of the identity attribute, if declared. Falls back to name if no identity attribute is declared.

ignore_failure(arg=nil)
immediate_notifications()
inspect()
is(*args)
load_prior_resource()
method_missing(method_symbol, *args, &block)

If an unknown method is invoked, determine whether the enclosing Provider‘s lexical scope can fulfill the request. E.g. This happens when the Resource‘s block invokes new_resource.

name(name=nil)
node()
noop(tf=nil)
not_if(command=nil, opts={}, &block)

If command is a block, returns false if the block returns true, true if it returns false. ("Do not run this resource if the block is true")

If the command is not a block, executes the command. If it returns a 0 exitstatus, returns false. ("Do not run this resource if the command returns 0")

### Parameters

command<String>: | A a string to execute.
opts<Hash>: | Options control the execution of the command
block<Proc>: | A ruby block to run. Ignored if a command is given.

### Evaluation

- evaluates to true if the block is false, or if the command returns a non-zero exit status.
- evaluates to false if the block is true, or if the command returns a 0 exit status.

notifies(*args)
notifies_delayed(action, resource_spec)
notifies_immediately(action, resource_spec)
only_if(command=nil, opts={}, &block)

If command is a block, returns true if the block returns true, false if it returns false. ("Only run this resource if the block is true")

If the command is not a block, executes the command. If it returns any status other than 0, it returns false (clearly, a 0 status code is true)

### Parameters

command<String>: | A a string to execute.
opts<Hash>: | Options control the execution of the command
block<Proc>: | A ruby block to run. Ignored if a command is given.

### Evaluation

- evaluates to true if the block is true, or if the command returns 0
- evaluates to false if the block is false, or if the command returns a non-zero exit code.

provider(arg=nil)
provider_for_action(action)
resolve_notification_references()

Iterates over all immediate and delayed notifications, calling resolve_resource_reference on each in turn, causing them to resolve lazy/forward references.

resources(*args)
retries(arg=nil)
retry_delay(arg=nil)
run_action(action, notification_type=nil, notifying_resource=nil)
should_skip?(action)

Evaluates not_if and only_if conditionals. Returns a falsey value if any of the conditionals indicate that this resource should be skipped, i.e., if an only_if evaluates to false or a not_if evaluates to true.

If this resource should be skipped, returns the first conditional that "fails" its check. Subsequent conditionals are not evaluated, so in general it‘s not a good idea to rely on side effects from not_if or only_if commands/blocks being evaluated.

state()

Returns a Hash of attribute => value for the state attributes declared in the resource‘s class definition.

subscribes(action, resources, timing=:delayed)
supports(args={})
to_hash()
to_json(*a)

Serialize this object as a hash

to_s()
to_text()
updated=(true_or_false)
updated?()
updated_by_last_action(true_or_false)
updated_by_last_action?()
validate_action(action)

[Validate]