Class: Puppet::Provider::Package

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

Direct Known Subclasses

Targetable

Defined Under Namespace

Classes: Targetable, Windows

Constant Summary

Constants inherited from Puppet::Provider

Confine

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

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

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

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.



7
8
9
10
11
12
13
14
# File 'lib/puppet/provider/package.rb', line 7

def self.prefetch(packages)
  instances.each do |prov|
    pkg = packages[prov.name]
    if pkg
      pkg.provider = prov
    end
  end
end

Instance Method Details

#execute(*args) ⇒ Object

Injects the resource’s environment variables into execute calls via ‘:custom_environment`. Providers using `execute()` directly get this automatically.



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/puppet/provider/package.rb', line 79

def execute(*args)
  env = package_environment
  unless env.empty?
    if args.last.is_a?(Hash)
      existing = args.last[:custom_environment] || {}
      args.last[:custom_environment] = existing.merge(env)
    else
      args << { :custom_environment => env }
    end
  end
  super(*args)
end

#flushObject

Clear out the cached values.



17
18
19
# File 'lib/puppet/provider/package.rb', line 17

def flush
  @property_hash.clear
end

#join_options(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Turns a array of options into flags to be passed to a command. The options can be passed as a string or hash. Note that passing a hash should only be used in case –foo=bar must be passed, which can be accomplished with:

install_options => [ { '--foo' => 'bar' } ]

Regular flags like ‘–foo’ must be passed as a string.

Parameters:

  • options (Array)

Returns:

  • Concatenated list of options



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/puppet/provider/package.rb', line 114

def join_options(options)
  return unless options

  options.collect do |val|
    case val
    when Hash
      val.keys.sort.collect do |k|
        "#{k}=#{val[k]}"
      end
    else
      val
    end
  end.flatten
end

#package_environmentHash<String, String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Environment variables parsed from the resource’s ‘environment` parameter, or an empty hash if none are set.

Returns:

  • (Hash<String, String>)

    Environment variables parsed from the resource’s ‘environment` parameter, or an empty hash if none are set.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/puppet/provider/package.rb', line 41

def package_environment
  env = {}

  return env unless resource.respond_to?(:parameters)

  env_param = resource.parameters[:environment]
  return env unless env_param

  envlist = env_param.value
  return env unless envlist

  envlist = [envlist] unless envlist.is_a? Array
  envlist.each do |setting|
    unless (match = /\A(\w+)=((.|\n)*)\z/.match(setting))
      warning _("Cannot understand environment setting %{setting}") % { setting: setting.inspect }
      next
    end
    var = match[1]
    value = match[2]

    if env.include?(var)
      warning _("Overriding environment setting '%{var}'") % { var: var }
    end

    if value.nil? || value.empty?
      msg = _("Empty environment setting '%{var}'") % { var: var }
      Puppet.warn_once('undefined_variables', "empty_env_var_#{var}", msg, resource.file, resource.line)
    end

    env[var] = value
  end

  env
end

#propertiesObject

Look up the current status.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/provider/package.rb', line 22

def properties
  if @property_hash.empty?
    # For providers that support purging, default to purged; otherwise default to absent
    # Purged is the "most uninstalled" a package can be, so a purged package will be in-sync with
    # either `ensure => absent` or `ensure => purged`; an absent package will be out of sync with `ensure => purged`.
    default_status = self.class.feature?(:purgeable) ? :purged : :absent
    @property_hash = query || { :ensure => default_status }
    @property_hash[:ensure] = default_status if @property_hash.empty?
  end
  @property_hash.dup
end

#validate_source(value) ⇒ Object



34
35
36
# File 'lib/puppet/provider/package.rb', line 34

def validate_source(value)
  true
end

#with_environment(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wraps a block with the resource’s environment variables applied via ‘Puppet::Util.withenv`. Use this around named command methods (e.g. `aptget`, `dpkg`, `rpm`) that bypass instance-level `execute`.



96
97
98
99
100
101
102
103
# File 'lib/puppet/provider/package.rb', line 96

def with_environment(&block)
  env = package_environment
  if env.empty?
    yield
  else
    Puppet::Util.withenv(env, &block)
  end
end