Class: Puppet::Provider::Package::Targetable
- Inherits:
-
Puppet::Provider::Package
- Object
- Puppet::Provider
- Puppet::Provider::Package
- Puppet::Provider::Package::Targetable
- 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
Constants included from Util
Util::ALNUM, Util::ALPHA, Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::ESCAPED, Util::HEX, Util::HttpProxy, Util::PUPPET_STACK_INSERTION_FRAME, Util::RESERVED, Util::RFC_3986_URI_REGEX, Util::UNRESERVED, Util::UNSAFE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Docs
Instance Attribute Summary
Attributes inherited from Puppet::Provider
Attributes included from Util::Docs
Class Method Summary collapse
-
.prefetch(packages) ⇒ Object
Prefetch our package list, yo.
-
.validate_command(cmd) ⇒ Object
Targetable providers use has_command/is_optional to defer validation of provider suitability.
Instance Method Summary collapse
-
#resource_or_provider_command ⇒ Object
Returns the resource command or provider command.
-
#to_s ⇒ Object
Return information about the package, its provider, and its (optional) command.
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, 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_backtrace, #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, create_erb, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, rfc2396_escape, safe_posix_fork, set_env, skip_external_facts, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, uri_unescape, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#display_mode, #normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Methods included from Util::Warnings
clear_warnings, debug_once, maybe_log, notice_once, warnonce
Methods included from Confiner
#confine, #confine_collection, #suitable?
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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppet/provider/package_targetable.rb', line 29 def self.prefetch(packages) catalog_packages = packages.values.first.catalog.resources.select { |p| p.provider.instance_of?(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 debug "Prefetched instance: %{name} via command: %{cmd}" % { name: instance.name, cmd: command || :default } end end end end package_commands 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.
56 57 58 59 60 61 62 63 |
# File 'lib/puppet/provider/package_targetable.rb', line 56 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_command ⇒ Object
Returns the resource command or provider command.
47 48 49 |
# File 'lib/puppet/provider/package_targetable.rb', line 47 def resource_or_provider_command resource.original_parameters[:command] || self.class.provider_command end |
#to_s ⇒ Object
Return information about the package, its provider, and its (optional) command.
67 68 69 70 |
# File 'lib/puppet/provider/package_targetable.rb', line 67 def to_s cmd = resource[:command] || :default "#{@resource}(provider=#{self.class.name})(command=#{cmd})" end |