Class: Chef::Provider::Package
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::Package
- Extended by:
- Mixin::SubclassDirective
- Defined in:
- lib/chef/provider/package.rb,
lib/chef/provider/package/apt.rb,
lib/chef/provider/package/bff.rb,
lib/chef/provider/package/cab.rb,
lib/chef/provider/package/deb.rb,
lib/chef/provider/package/dnf.rb,
lib/chef/provider/package/ips.rb,
lib/chef/provider/package/msu.rb,
lib/chef/provider/package/rpm.rb,
lib/chef/provider/package/yum.rb,
lib/chef/provider/package/dpkg.rb,
lib/chef/provider/package/snap.rb,
lib/chef/provider/package/pacman.rb,
lib/chef/provider/package/zypper.rb,
lib/chef/provider/package/habitat.rb,
lib/chef/provider/package/openbsd.rb,
lib/chef/provider/package/paludis.rb,
lib/chef/provider/package/portage.rb,
lib/chef/provider/package/smartos.rb,
lib/chef/provider/package/snap_tm.rb,
lib/chef/provider/package/solaris.rb,
lib/chef/provider/package/windows.rb,
lib/chef/provider/package/homebrew.rb,
lib/chef/provider/package/macports.rb,
lib/chef/provider/package/rubygems.rb,
lib/chef/provider/package/chocolatey.rb,
lib/chef/provider/package/powershell.rb,
lib/chef/provider/package/dnf/version.rb,
lib/chef/provider/package/windows/exe.rb,
lib/chef/provider/package/windows/msi.rb,
lib/chef/provider/package/yum/version.rb,
lib/chef/provider/package/freebsd/base.rb,
lib/chef/provider/package/freebsd/port.rb,
lib/chef/provider/package/freebsd/pkgng.rb,
lib/chef/provider/package/yum/rpm_utils.rb,
lib/chef/provider/package/yum/yum_cache.rb,
lib/chef/provider/package/zypper/version.rb,
lib/chef/provider/package/dnf/python_helper.rb,
lib/chef/provider/package/yum/python_helper.rb,
lib/chef/provider/package/windows/registry_uninstall_entry.rb
Direct Known Subclasses
Apt, Bff, Cab, Chocolatey, Dnf, Dpkg, Freebsd::Base, Habitat, Homebrew, Ips, Macports, Msu, Openbsd, Pacman, Paludis, Portage, Powershell, Rpm, Rubygems, SmartOS, Snap, Solaris, Windows, Yum, Zypper
Defined Under Namespace
Modules: Deb, Freebsd Classes: Apt, Bff, Cab, Chocolatey, Dnf, Dpkg, Habitat, Homebrew, Ips, Macports, Msu, Openbsd, Pacman, Paludis, Portage, Powershell, Rpm, Rubygems, SmartOS, Snap, SnapTM, Solaris, Windows, Yum, Zypper
Instance Attribute Summary collapse
-
#candidate_version ⇒ Array, String
Hook that subclasses use to populate the candidate_version(s).
Attributes inherited from Chef::Provider
#action, #after_resource, #current_resource, #logger, #new_resource, #run_context
Instance Method Summary collapse
-
#as_array(thing) ⇒ Object
helper method used by subclasses.
- #check_resource_semantics! ⇒ Object
- #define_resource_requirements ⇒ Object
-
#expand_options(options) ⇒ Object
used by subclasses.
- #have_any_matching_version? ⇒ Boolean
-
#initialize(new_resource, run_context) ⇒ Package
constructor
A new instance of Package.
- #install_package(name, version) ⇒ Object
- #load_current_resource ⇒ Object
- #lock_package(name, version) ⇒ Object
- #multipackage_api_adapter(name, version) ⇒ Object
- #options ⇒ Object
-
#package_locked(name, version) ⇒ Object
for multipackage just implement packages_all_locked? properly and omit implementing this API.
-
#prepare_for_installation ⇒ Object
Subclasses will override this to a method and provide a preseed file path.
- #preseed_package(file) ⇒ Object
- #purge_package(name, version) ⇒ Object
- #reconfig_package(name) ⇒ Object
- #remove_package(name, version) ⇒ Object
- #removing_package? ⇒ Boolean
-
#target_version_already_installed?(current_version, target_version) ⇒ Boolean
This method performs a strict equality check between two strings representing version numbers.
- #unlock_package(name, version) ⇒ Object
- #upgrade_package(name, version) ⇒ Object
-
#version_compare(v1, v2) ⇒ Object
This function compares two version numbers and returns ‘spaceship operator’ style results, ie: if v1 < v2 then return -1 if v1 = v2 then return 0 if v1 > v2 then return 1 if v1 and v2 are not comparable then return nil.
-
#version_equals?(v1, v2) ⇒ Boolean
This method performs a strict equality check between two strings representing version numbers.
-
#version_requirement_satisfied?(current_version, new_version) ⇒ Boolean
Check the current_version against the new_resource.version, possibly using fuzzy matching criteria.
Methods included from Mixin::SubclassDirective
Methods inherited from Chef::Provider
action, action_description, action_descriptions, #action_nothing, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #cookbook_name, #description, #events, include_resource_dsl?, include_resource_dsl_module, #introduced, #load_after_resource, #node, #process_resource_requirements, provides, provides?, #recipe_name, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use, use_inline_resources, #validate_required_properties!, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::Provides
#provided_as, #provides, #provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from DSL::Secret
#default_secret_config, #default_secret_service, #secret, #with_secret_config, #with_secret_service
Methods included from DSL::RenderHelpers
#render_json, #render_toml, #render_yaml
Methods included from DSL::ReaderHelpers
#parse_file, #parse_json, #parse_toml, #parse_yaml
Methods included from DSL::Powershell
Methods included from DSL::RegistryHelper
#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?
Methods included from DSL::ChefVault
#chef_vault, #chef_vault_item, #chef_vault_item_for_environment
Methods included from DSL::DataQuery
#data_bag, #data_bag_item, #search, #tagged?
Methods included from EncryptedDataBagItem::CheckEncrypted
Methods included from DSL::PlatformIntrospection
#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Methods included from DSL::Recipe
#exec, #have_resource_class_for?, #resource_class_for
Methods included from DSL::Definitions
add_definition, #evaluate_resource_definition, #has_resource_definition?
Methods included from DSL::Resources
add_resource_dsl, remove_resource_dsl
Methods included from DSL::Cheffish
Methods included from DSL::RebootPending
Methods included from DSL::IncludeRecipe
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context
Methods included from DSL::Compliance
#include_input, #include_profile, #include_waiver
Constructor Details
#initialize(new_resource, run_context) ⇒ Package
Returns a new instance of Package.
72 73 74 75 |
# File 'lib/chef/provider/package.rb', line 72 def initialize(new_resource, run_context) super @candidate_version = nil end |
Instance Attribute Details
#candidate_version ⇒ Array, String
Hook that subclasses use to populate the candidate_version(s)
70 71 72 |
# File 'lib/chef/provider/package.rb', line 70 def candidate_version @candidate_version end |
Instance Method Details
#as_array(thing) ⇒ Object
helper method used by subclasses
388 389 390 |
# File 'lib/chef/provider/package.rb', line 388 def as_array(thing) [ thing ].flatten end |
#check_resource_semantics! ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/chef/provider/package.rb', line 81 def check_resource_semantics! # FIXME: this is not universally true and subclasses are needing to override this and no-ops it. It should be turned into # another "subclass_directive" and the apt and yum providers should declare that they need this behavior. if new_resource.package_name.is_a?(Array) && !new_resource.source.nil? raise Chef::Exceptions::InvalidResourceSpecification, "You may not specify both multipackage and source" end end |
#define_resource_requirements ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/chef/provider/package.rb', line 91 def define_resource_requirements # XXX: upgrade with a specific version doesn't make a whole lot of sense, but why don't we throw this anyway if it happens? # if not, shouldn't we raise to tell the user to use install instead of upgrade if they want to pin a version? requirements.assert(:install) do |a| a.assertion { candidates_exist_for_all_forced_changes? } a.(Chef::Exceptions::Package, "No version specified, and no candidate version available for #{forced_packages_missing_candidates.join(", ")}") a.whyrun("Assuming a repository that offers #{forced_packages_missing_candidates.join(", ")} would have been configured") end # XXX: Does it make sense to pass in a source with :upgrade? Probably # not, but as with the above comment, we don't yet enforce such a thing, # so we'll just leave things as-is for now. requirements.assert(:upgrade, :install) do |a| a.assertion { candidates_exist_for_all_uninstalled? || new_resource.source } a.(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(", ")}") a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(", ")} would have been configured") end end |
#expand_options(options) ⇒ Object
used by subclasses. deprecated. use #a_to_s instead.
306 307 308 309 310 311 312 313 314 |
# File 'lib/chef/provider/package.rb', line 306 def () # its deprecated but still work to do to deprecate it fully # Chef.deprecated(:package_misc, "expand_options is deprecated, use shell_out instead") if " #{.is_a?(Array) ? Shellwords.join() : }" else "" end end |
#have_any_matching_version? ⇒ Boolean
184 185 186 187 188 189 190 |
# File 'lib/chef/provider/package.rb', line 184 def have_any_matching_version? f = [] new_version_array.each_with_index do |item, index| f << (item == current_version_array[index]) end f.any? end |
#install_package(name, version) ⇒ Object
273 274 275 |
# File 'lib/chef/provider/package.rb', line 273 def install_package(name, version) raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :install" end |
#load_current_resource ⇒ Object
89 |
# File 'lib/chef/provider/package.rb', line 89 def load_current_resource; end |
#lock_package(name, version) ⇒ Object
297 298 299 |
# File 'lib/chef/provider/package.rb', line 297 def lock_package(name, version) raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :lock" ) end |
#multipackage_api_adapter(name, version) ⇒ Object
use composition rather than inheritance
265 266 267 268 269 270 271 |
# File 'lib/chef/provider/package.rb', line 265 def multipackage_api_adapter(name, version) if use_multipackage_api? yield [name].flatten, [version].flatten else yield name, version end end |
#options ⇒ Object
77 78 79 |
# File 'lib/chef/provider/package.rb', line 77 def new_resource. end |
#package_locked(name, version) ⇒ Object
for multipackage just implement packages_all_locked? properly and omit implementing this API
256 257 258 |
# File 'lib/chef/provider/package.rb', line 256 def package_locked(name, version) raise Chef::Exceptions::UnsupportedAction, "#{self} has no way to detect if package is locked" end |
#prepare_for_installation ⇒ Object
Subclasses will override this to a method and provide a preseed file path
261 |
# File 'lib/chef/provider/package.rb', line 261 def prepare_for_installation; end |
#preseed_package(file) ⇒ Object
289 290 291 |
# File 'lib/chef/provider/package.rb', line 289 def preseed_package(file) raise Chef::Exceptions::UnsupportedAction, "#{self} does not support pre-seeding package install/upgrade instructions" end |
#purge_package(name, version) ⇒ Object
285 286 287 |
# File 'lib/chef/provider/package.rb', line 285 def purge_package(name, version) raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :purge" end |
#reconfig_package(name) ⇒ Object
293 294 295 |
# File 'lib/chef/provider/package.rb', line 293 def reconfig_package(name) raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :reconfig" ) end |
#remove_package(name, version) ⇒ Object
281 282 283 |
# File 'lib/chef/provider/package.rb', line 281 def remove_package(name, version) raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :remove" end |
#removing_package? ⇒ Boolean
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/chef/provider/package.rb', line 192 def removing_package? if !current_version_array.any? # ! any? means it's all nil's, which means nothing is installed false elsif !new_version_array.any? true # remove any version of all packages elsif have_any_matching_version? true # remove the version we have else false # we don't have the version we want to remove end end |
#target_version_already_installed?(current_version, target_version) ⇒ Boolean
This method performs a strict equality check between two strings representing version numbers
This function will eventually be deprecated in favour of the below version_equals function.
340 341 342 |
# File 'lib/chef/provider/package.rb', line 340 def target_version_already_installed?(current_version, target_version) version_equals?(current_version, target_version) end |
#unlock_package(name, version) ⇒ Object
301 302 303 |
# File 'lib/chef/provider/package.rb', line 301 def unlock_package(name, version) raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :unlock" ) end |
#upgrade_package(name, version) ⇒ Object
277 278 279 |
# File 'lib/chef/provider/package.rb', line 277 def upgrade_package(name, version) raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :upgrade" end |
#version_compare(v1, v2) ⇒ Object
This function compares two version numbers and returns ‘spaceship operator’ style results, ie: if v1 < v2 then return -1 if v1 = v2 then return 0 if v1 > v2 then return 1 if v1 and v2 are not comparable then return nil
By default, this function will use Gem::Version comparison. Subclasses can reimplement this method for package-management system specific versions.
(In other words, pull requests to introduce domain specific mangling of versions into this method will be closed – that logic must go into the subclass – we understand that this is far from perfect but it is a better default than outright buggy things like v1.to_f <=> v2.to_f)
368 369 370 371 372 373 |
# File 'lib/chef/provider/package.rb', line 368 def version_compare(v1, v2) gem_v1 = Gem::Version.new(v1.gsub(/\A\s*(#{Gem::Version::VERSION_PATTERN}).*/, '\1')) gem_v2 = Gem::Version.new(v2.gsub(/\A\s*(#{Gem::Version::VERSION_PATTERN}).*/, '\1')) gem_v1 <=> gem_v2 end |
#version_equals?(v1, v2) ⇒ Boolean
This method performs a strict equality check between two strings representing version numbers
349 350 351 352 353 |
# File 'lib/chef/provider/package.rb', line 349 def version_equals?(v1, v2) return false unless v1 && v2 v1 == v2 end |
#version_requirement_satisfied?(current_version, new_version) ⇒ Boolean
Check the current_version against the new_resource.version, possibly using fuzzy matching criteria.
Subclasses MAY override this to provide fuzzy matching on the resource (‘>=’ and ‘~>’ stuff)
‘version_satisfied_by?(version, constraint)` might be a better name to make this generic.
382 383 384 |
# File 'lib/chef/provider/package.rb', line 382 def version_requirement_satisfied?(current_version, new_version) target_version_already_installed?(current_version, new_version) end |