summaryrefslogtreecommitdiff
path: root/lib/chef/resource
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/resource')
-rw-r--r--lib/chef/resource/apt_package.rb15
-rw-r--r--lib/chef/resource/chef_gem.rb28
-rw-r--r--lib/chef/resource/dpkg_package.rb5
-rw-r--r--lib/chef/resource/easy_install_package.rb27
-rw-r--r--lib/chef/resource/freebsd_package.rb3
-rw-r--r--lib/chef/resource/gem_package.rb25
-rw-r--r--lib/chef/resource/homebrew_package.rb15
-rw-r--r--lib/chef/resource/ips_package.rb15
-rw-r--r--lib/chef/resource/macports_package.rb1
-rw-r--r--lib/chef/resource/openbsd_package.rb1
-rw-r--r--lib/chef/resource/package.rb76
-rw-r--r--lib/chef/resource/pacman_package.rb1
-rw-r--r--lib/chef/resource/paludis_package.rb6
-rw-r--r--lib/chef/resource/portage_package.rb1
-rw-r--r--lib/chef/resource/rpm_package.rb14
-rw-r--r--lib/chef/resource/smartos_package.rb1
-rw-r--r--lib/chef/resource/solaris_package.rb1
-rw-r--r--lib/chef/resource/windows_package.rb73
-rw-r--r--lib/chef/resource/yum_package.rb52
-rw-r--r--lib/chef/resource/zypper_package.rb1
20 files changed, 71 insertions, 290 deletions
diff --git a/lib/chef/resource/apt_package.rb b/lib/chef/resource/apt_package.rb
index ca119b50c4..b15a86bddf 100644
--- a/lib/chef/resource/apt_package.rb
+++ b/lib/chef/resource/apt_package.rb
@@ -22,21 +22,10 @@ require 'chef/provider/package/apt'
class Chef
class Resource
class AptPackage < Chef::Resource::Package
-
+ resource_name :apt_package
provides :package, os: "linux", platform_family: [ "debian" ]
- def initialize(name, run_context=nil)
- super
- @default_release = nil
- end
-
- def default_release(arg=nil)
- set_or_return(
- :default_release,
- arg,
- :kind_of => [ String ]
- )
- end
+ property :default_release, String, desired_state: false
end
end
diff --git a/lib/chef/resource/chef_gem.rb b/lib/chef/resource/chef_gem.rb
index 7e9d21ebd2..b2cd9da101 100644
--- a/lib/chef/resource/chef_gem.rb
+++ b/lib/chef/resource/chef_gem.rb
@@ -22,29 +22,13 @@ require 'chef/resource/gem_package'
class Chef
class Resource
class ChefGem < Chef::Resource::Package::GemPackage
+ resource_name :chef_gem
- def initialize(name, run_context=nil)
- super
- @compile_time = Chef::Config[:chef_gem_compile_time]
- @gem_binary = RbConfig::CONFIG['bindir'] + "/gem"
- end
-
- # The chef_gem resources is for installing gems to the current gem environment only for use by Chef cookbooks.
- def gem_binary(arg=nil)
- if arg
- raise ArgumentError, "The chef_gem resource is restricted to the current gem environment, use gem_package to install to other environments."
- end
-
- @gem_binary
- end
-
- def compile_time(arg=nil)
- set_or_return(
- :compile_time,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
+ property :gem_binary, default: "#{RbConfig::CONFIG['bindir']}/gem",
+ callbacks: {
+ "The chef_gem resource is restricted to the current gem environment, use gem_package to install to other environments." => proc { false }
+ }
+ property :compile_time, [ true, false ], default: lazy { Chef::Config[:chef_gem_compile_time] }, desired_state: false
def after_created
# Chef::Resource.run_action: Caveat: this skips Chef::Runner.run_action, where notifications are handled
diff --git a/lib/chef/resource/dpkg_package.rb b/lib/chef/resource/dpkg_package.rb
index 9288c18632..7d58385c6d 100644
--- a/lib/chef/resource/dpkg_package.rb
+++ b/lib/chef/resource/dpkg_package.rb
@@ -21,11 +21,10 @@ require 'chef/resource/package'
class Chef
class Resource
class DpkgPackage < Chef::Resource::Package
- provides :dpkg_package, os: "linux"
-
resource_name :dpkg_package
+ provides :dpkg_package, os: "linux"
- property :source, [String, Array, nil]
+ property :source, [ String, Array, nil ]
end
end
end
diff --git a/lib/chef/resource/easy_install_package.rb b/lib/chef/resource/easy_install_package.rb
index df4cee1ab3..ea646ecc9f 100644
--- a/lib/chef/resource/easy_install_package.rb
+++ b/lib/chef/resource/easy_install_package.rb
@@ -21,30 +21,11 @@ require 'chef/resource/package'
class Chef
class Resource
class EasyInstallPackage < Chef::Resource::Package
+ resource_name :easy_install_package
- def easy_install_binary(arg=nil)
- set_or_return(
- :easy_install_binary,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def python_binary(arg=nil)
- set_or_return(
- :python_install_binary,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def module_name(arg=nil)
- set_or_return(
- :module_name,
- arg,
- :kind_of => [ String ]
- )
- end
+ property :easy_install_binary, String, desired_state: false
+ property :python_binary, String, desired_state: false
+ property :module_name, String, desired_state: false
end
end
diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb
index c7c43450ba..e656f1c3e3 100644
--- a/lib/chef/resource/freebsd_package.rb
+++ b/lib/chef/resource/freebsd_package.rb
@@ -29,6 +29,7 @@ class Chef
class FreebsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
+ resource_name :freebsd_package
provides :package, platform: "freebsd"
def after_created
@@ -48,7 +49,7 @@ class Chef
end
def assign_provider
- @provider = if @source.to_s =~ /^ports$/i
+ @provider = if source.to_s =~ /^ports$/i
Chef::Provider::Package::Freebsd::Port
elsif supports_pkgng?
Chef::Provider::Package::Freebsd::Pkgng
diff --git a/lib/chef/resource/gem_package.rb b/lib/chef/resource/gem_package.rb
index b981797876..e1a089e1f2 100644
--- a/lib/chef/resource/gem_package.rb
+++ b/lib/chef/resource/gem_package.rb
@@ -21,24 +21,12 @@ require 'chef/resource/package'
class Chef
class Resource
class GemPackage < Chef::Resource::Package
+ resource_name :gem_package
- def initialize(name, run_context=nil)
- super
- @clear_sources = false
- end
-
- def source(arg=nil)
- set_or_return(:source, arg, :kind_of => [ String, Array ])
- end
-
- def clear_sources(arg=nil)
- set_or_return(:clear_sources, arg, :kind_of => [ TrueClass, FalseClass ])
- end
-
+ property :source, [ String, Array ]
+ property :clear_sources, [ true, false ], default: false, desired_state: false
# Sets a custom gem_binary to run for gem commands.
- def gem_binary(gem_cmd=nil)
- set_or_return(:gem_binary,gem_cmd,:kind_of => [ String ])
- end
+ property :gem_binary, String, desired_state: false
##
# Options for the gem install, either a Hash or a String. When a hash is
@@ -46,10 +34,7 @@ class Chef
# gem will be installed via the gems API. When a String is given, the gem
# will be installed by shelling out to the gem command. Using a Hash of
# options with an explicit gem_binary will result in undefined behavior.
- def options(opts=nil)
- set_or_return(:options,opts,:kind_of => [String,Hash])
- end
-
+ property :options, [ String, Hash, nil ], desired_state: false
end
end
diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb
index 048ba6b3aa..e070318c45 100644
--- a/lib/chef/resource/homebrew_package.rb
+++ b/lib/chef/resource/homebrew_package.rb
@@ -24,21 +24,10 @@ require 'chef/resource/package'
class Chef
class Resource
class HomebrewPackage < Chef::Resource::Package
-
+ resource_name :homebrew_package
provides :package, os: "darwin"
- def initialize(name, run_context=nil)
- super
- @homebrew_user = nil
- end
-
- def homebrew_user(arg=nil)
- set_or_return(
- :homebrew_user,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
+ property :homebrew_user, [ String, Integer ]
end
end
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index 2bf8e1dba8..cee02d52fd 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -22,24 +22,13 @@ require 'chef/provider/package/ips'
class Chef
class Resource
class IpsPackage < ::Chef::Resource::Package
-
+ resource_name :ips_package
provides :package, os: "solaris2"
provides :ips_package, os: "solaris2"
allowed_actions :install, :remove, :upgrade
- def initialize(name, run_context = nil)
- super(name, run_context)
- @accept_license = false
- end
-
- def accept_license(arg=nil)
- set_or_return(
- :purge,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
+ property :accept_license, [ true, false ], default: false, desired_state: false
end
end
end
diff --git a/lib/chef/resource/macports_package.rb b/lib/chef/resource/macports_package.rb
index 5843016897..61d5ed23c4 100644
--- a/lib/chef/resource/macports_package.rb
+++ b/lib/chef/resource/macports_package.rb
@@ -21,6 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class MacportsPackage < Chef::Resource::Package
+ resource_name :macports_package
end
end
end
diff --git a/lib/chef/resource/openbsd_package.rb b/lib/chef/resource/openbsd_package.rb
index 9ae8813d69..da3a241216 100644
--- a/lib/chef/resource/openbsd_package.rb
+++ b/lib/chef/resource/openbsd_package.rb
@@ -28,6 +28,7 @@ class Chef
class OpenbsdPackage < Chef::Resource::Package
include Chef::Mixin::ShellOut
+ resource_name :openbsd_package
provides :package, os: "openbsd"
end
end
diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb
index c73810a118..d190479a29 100644
--- a/lib/chef/resource/package.rb
+++ b/lib/chef/resource/package.rb
@@ -22,79 +22,25 @@ require 'chef/resource'
class Chef
class Resource
class Package < Chef::Resource
- identity_attr :package_name
-
- state_attrs :version, :options
+ resource_name :package
default_action :install
allowed_actions :install, :upgrade, :remove, :purge, :reconfig
- def initialize(name, run_context=nil)
+ def initialize(name, *args)
+ # We capture name here, before it gets coerced to name
+ package_name name
super
- options nil
- package_name name
- response_file nil
- response_file_variables Hash.new
- source nil
- version nil
- timeout nil
- end
-
- def package_name(arg=nil)
- set_or_return(
- :package_name,
- arg,
- :kind_of => [ String, Array ]
- )
end
- def version(arg=nil)
- set_or_return(
- :version,
- arg,
- :kind_of => [ String, Array ]
- )
- end
+ property :package_name, [ String, Array ], identity: true
- def response_file(arg=nil)
- set_or_return(
- :response_file,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def response_file_variables(arg=nil)
- set_or_return(
- :response_file_variables,
- arg,
- :kind_of => [ Hash ]
- )
- end
-
- def source(arg=nil)
- set_or_return(
- :source,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def options(arg=nil)
- set_or_return(
- :options,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def timeout(arg=nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [String, Integer]
- )
- end
+ property :version, [ String, Array ]
+ property :options, String
+ property :response_file, String, desired_state: false
+ property :response_file_variables, Hash, default: lazy { {} }, desired_state: false
+ property :source, String, desired_state: false
+ property :timeout, [ String, Integer ], desired_state: false
end
end
diff --git a/lib/chef/resource/pacman_package.rb b/lib/chef/resource/pacman_package.rb
index 54b8efc4c2..8aabf8be77 100644
--- a/lib/chef/resource/pacman_package.rb
+++ b/lib/chef/resource/pacman_package.rb
@@ -21,6 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class PacmanPackage < Chef::Resource::Package
+ resource_name :pacman_package
provides :pacman_package, os: "linux"
end
end
diff --git a/lib/chef/resource/paludis_package.rb b/lib/chef/resource/paludis_package.rb
index 56c47bc141..e93e6288b8 100644
--- a/lib/chef/resource/paludis_package.rb
+++ b/lib/chef/resource/paludis_package.rb
@@ -22,14 +22,12 @@ require 'chef/provider/package/paludis'
class Chef
class Resource
class PaludisPackage < Chef::Resource::Package
+ resource_name :paludis_package
provides :paludis_package, os: "linux"
allowed_actions :install, :remove, :upgrade
- def initialize(name, run_context=nil)
- super(name, run_context)
- @timeout = 3600
- end
+ property :timeout, default: 3600
end
end
end
diff --git a/lib/chef/resource/portage_package.rb b/lib/chef/resource/portage_package.rb
index 1af48702fa..2b75f6a651 100644
--- a/lib/chef/resource/portage_package.rb
+++ b/lib/chef/resource/portage_package.rb
@@ -21,6 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class PortagePackage < Chef::Resource::Package
+ resource_name :portage_package
def initialize(name, run_context=nil)
super
@provider = Chef::Provider::Package::Portage
diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb
index b8b5144a42..4f6dc4c0a6 100644
--- a/lib/chef/resource/rpm_package.rb
+++ b/lib/chef/resource/rpm_package.rb
@@ -22,20 +22,10 @@ require 'chef/provider/package/rpm'
class Chef
class Resource
class RpmPackage < Chef::Resource::Package
+ resource_name :rpm_package
provides :rpm_package, os: [ "linux", "aix" ]
- def initialize(name, run_context=nil)
- super
- @allow_downgrade = false
- end
-
- def allow_downgrade(arg=nil)
- set_or_return(
- :allow_downgrade,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
+ property :allow_downgrade, [ true, false ], default: false, desired_state: false
end
end
diff --git a/lib/chef/resource/smartos_package.rb b/lib/chef/resource/smartos_package.rb
index b8bd940c24..34e704a856 100644
--- a/lib/chef/resource/smartos_package.rb
+++ b/lib/chef/resource/smartos_package.rb
@@ -22,6 +22,7 @@ require 'chef/provider/package/smartos'
class Chef
class Resource
class SmartosPackage < Chef::Resource::Package
+ resource_name :smartos_package
provides :package, os: "solaris2", platform_family: "smartos"
end
end
diff --git a/lib/chef/resource/solaris_package.rb b/lib/chef/resource/solaris_package.rb
index a98fb8b4fa..4ce38bd098 100644
--- a/lib/chef/resource/solaris_package.rb
+++ b/lib/chef/resource/solaris_package.rb
@@ -23,6 +23,7 @@ require 'chef/provider/package/solaris'
class Chef
class Resource
class SolarisPackage < Chef::Resource::Package
+ resource_name :solaris_package
provides :package, os: "solaris2", platform_family: "nexentacore"
provides :package, os: "solaris2", platform_family: "solaris2", platform_version: "<= 5.10"
end
diff --git a/lib/chef/resource/windows_package.rb b/lib/chef/resource/windows_package.rb
index f11b7b8b3b..4965f3f117 100644
--- a/lib/chef/resource/windows_package.rb
+++ b/lib/chef/resource/windows_package.rb
@@ -26,74 +26,21 @@ class Chef
class WindowsPackage < Chef::Resource::Package
include Chef::Mixin::Uris
+ resource_name :windows_package
provides :windows_package, os: "windows"
provides :package, os: "windows"
allowed_actions :install, :remove
- def initialize(name, run_context=nil)
- super
- @source ||= source(@package_name)
-
- # Unique to this resource
- @installer_type = nil
- @timeout = 600
- # In the past we accepted return code 127 for an unknown reason and 42 because of a bug
- @returns = [ 0 ]
- end
-
- def installer_type(arg=nil)
- set_or_return(
- :installer_type,
- arg,
- :kind_of => [ Symbol ]
- )
- end
-
- def timeout(arg=nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
-
- def returns(arg=nil)
- set_or_return(
- :returns,
- arg,
- :kind_of => [ String, Integer, Array ]
- )
- end
-
- def source(arg=nil)
- if arg == nil
- @source
- else
- raise ArgumentError, "Bad type for WindowsPackage resource, use a String" unless arg.is_a?(String)
- if uri_scheme?(arg)
- @source = arg
- else
- @source = Chef::Util::PathHelper.canonical_path(arg, false)
- end
- end
- end
-
- def checksum(arg=nil)
- set_or_return(
- :checksum,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def remote_file_attributes(arg=nil)
- set_or_return(
- :remote_file_attributes,
- arg,
- :kind_of => [ Hash ]
- )
- end
+ # Unique to this resource
+ property :installer_type, Symbol
+ property :timeout, [ String, Integer ], default: 600
+ # In the past we accepted return code 127 for an unknown reason and 42 because of a bug
+ property :returns, [ String, Integer, Array ], default: [ 0 ], desired_state: false
+ property :source, String, name_property: true,
+ coerce: proc { |s| uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false) }
+ property :checksum, String, desired_state: false
+ property :remote_file_attributes, Hash, desired_state: false
end
end
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index 50ba13ce65..95ab5ef125 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -22,49 +22,25 @@ require 'chef/provider/package/yum'
class Chef
class Resource
class YumPackage < Chef::Resource::Package
+ resource_name :yum_package
provides :package, os: "linux", platform_family: [ "rhel", "fedora" ]
- def initialize(name, run_context=nil)
- super
- @flush_cache = { :before => false, :after => false }
- @allow_downgrade = false
- @yum_binary = nil
- end
-
# Install a specific arch
- def arch(arg=nil)
- set_or_return(
- :arch,
- arg,
- :kind_of => [ String, Array ]
- )
- end
-
- def flush_cache(args={})
- if args.is_a? Array
- args.each { |arg| @flush_cache[arg] = true }
- elsif args.any?
- @flush_cache = args
+ property :arch, [ String, Array ]
+ property :flush_cache, Hash, default: { before: false, after: false }, coerce: proc { |v|
+ # TODO these append rather than set. This is probably wrong behavior, but we're preserving it until we know
+ if v.is_a?(Array)
+ v.each { |arg| flush_cache[arg] = true }
+ flush_cache
+ elsif v.any?
+ v
else
- @flush_cache
+ # TODO calling flush_cache({}) does a get instead of a set. This is probably wrong behavior, but we're preserving it until we know
+ flush_cache
end
- end
-
- def allow_downgrade(arg=nil)
- set_or_return(
- :allow_downgrade,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
- def yum_binary(arg=nil)
- set_or_return(
- :yum_binary,
- arg,
- :kind_of => [ String ]
- )
- end
+ }
+ property :allow_downgrade, [ true, false ], default: false
+ property :yum_binary, String
end
end
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index f09a20e2c6..c86546eb46 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -21,6 +21,7 @@ require 'chef/resource/package'
class Chef
class Resource
class ZypperPackage < Chef::Resource::Package
+ resource_name :zypper_package
provides :package, platform_family: "suse"
end
end