Class: Puppet::Provider::Package::Targetable

Inherits:
Puppet::Provider::Package show all
Defined in:
lib/puppet/provider/package_targetable.rb

Overview

But `query` in the provider depends upon whether a `command` attribute is defined for the resource. This is a Catch-22.

Instead …

Inspect any package to access the catalog (every package includes a reference to the catalog). Inspect the catalog to find all of the `command` attributes for all of the packages of this class. Find all of the package instances using each package `command`, including the default provider command. Assign each instance's `provider` by selecting it from the `packages` hash passed to `prefetch`, based upon `name` and `command`.

The original `command` parameter in the catalog is not populated by the default (`:default`) for the parameter in type/package.rb. Rather, the result of the `original_parameters` is `nil` when the `command` parameter is undefined in the catalog.

Constant Summary

Constants inherited from Puppet::Provider

Confine

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::RFC_3986_URI_REGEX

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes inherited from Puppet::Provider

#resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Provider::Package

#flush, #join_options, #properties, #validate_source

Methods inherited from Puppet::Provider

#<=>, #clear, #command, command, commands, declared_feature?, default?, default_match, defaultfor, #execfail, execfail, #execpipe, execpipe, #execute, execute, fact_match, feature_match, #flush, #get, has_command, #initialize, initvars, #inspect, instances, mk_resource_methods, #name, notdefaultfor, optional_commands, post_resource_eval, #set, some_default_match, specificity, supports_parameter?

Methods included from Util::Logging

#clear_deprecation_warnings, #debug, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning, #send_log, setup_facter_logging!, #warn_once

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::POSIX

#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

Methods included from Confiner

#confine, #confine_collection, #suitable?

Methods included from Util::Warnings

clear_warnings, debug_once, maybe_log, notice_once, warnonce

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail

Constructor Details

This class inherits a constructor from Puppet::Provider

Class Method Details

.prefetch(packages) ⇒ Object

Prefetch our package list, yo.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet/provider/package_targetable.rb', line 27

def self.prefetch(packages)
  catalog_packages = packages.first[1]::catalog::resources.select{ |p| p.provider.class == self }
  package_commands = catalog_packages.map { |catalog_package| catalog_package::original_parameters[:command] }.uniq
  package_commands.each do |command|
    instances(command).each do |instance|
      catalog_packages.each do |catalog_package|
        if catalog_package[:name] == instance.name && catalog_package::original_parameters[:command] == command
          catalog_package.provider = instance
          self.debug "Prefetched instance: %{name} via command: %{command}" % { name: instance.name, cmd: (command || :default)}
        end
      end
    end
  end
end

.validate_command(cmd) ⇒ Object

Targetable providers use has_command/is_optional to defer validation of provider suitability. Evaluate provider suitability here and now by validating that the command is defined and exists.

cmd: the full path to the package command.


53
54
55
56
57
58
59
60
# File 'lib/puppet/provider/package_targetable.rb', line 53

def self.validate_command(cmd)
  unless cmd
    raise Puppet::Error, _("Provider %{name} package command is not functional on this host") % { name: name }
  end
  unless File.file?(cmd)
    raise Puppet::Error, _("Provider %{name} package command '%{cmd}' does not exist on this host") % { name: name, cmd: cmd }
  end
end

Instance Method Details

#resource_or_provider_commandObject

Returns the resource command or provider command.


44
45
46
# File 'lib/puppet/provider/package_targetable.rb', line 44

def resource_or_provider_command
  resource::original_parameters[:command] || self.class.provider_command
end

#to_sObject

Return information about the package, its provider, and its (optional) command.


64
65
66
67
# File 'lib/puppet/provider/package_targetable.rb', line 64

def to_s
  cmd = resource[:command] || :default
  "#{@resource}(provider=#{self.class.name})(command=#{cmd})"
end