Class: Puppet::Property::Ensure

Inherits:
Puppet::Property show all
Defined in:
lib/puppet/property/ensure.rb

Overview

This property is automatically added to any Type that responds to the methods ‘exists?’, ‘create’, and ‘destroy’.

Ensure defaults to having the wanted _(should)_ value ‘:present`.

Constant Summary

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Constants included from Util

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

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::Logging

Util::Logging::FILE_AND_LINE, Util::Logging::FILE_NO_LINE, Util::Logging::MM, Util::Logging::NO_FILE_LINE, Util::Logging::SUPPRESS_FILE_LINE

Instance Attribute Summary

Attributes inherited from Puppet::Property

#noop, #shouldorig

Attributes inherited from Puppet::Parameter

#name, #parent, #resource, #sensitive

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Property

#call_provider, #event, #event_name, idempotent, idempotent=, #idempotent?, #insync?, #insync_values?, #is_to_s, #log, #match_all?, method_added, #name, newvalue, #property_matches?, #safe_insync?, #set, #should, #should=, #should_to_s, #sync, #unsafe_validate, #validate_features_per_value, #value, #value=, value_name, value_option

Methods inherited from Puppet::Parameter

aliasvalue, defaultto, desc, doc, #file, #format, format_value_for_display, #initialize, initvars, isnamevar, isnamevar?, #isnamevar?, isrequired, #line, #log, #metaparam?, munge, #munge, newvalues, nodefault, #noop, #path, #pathbuilder, #provider, proxymethods, #remove, #required?, required?, #tags, #to_s, unmunge, #unmunge, #unsafe_munge, #unsafe_validate, validate, #validate, #value, #value=, #version

Methods included from Util::Docs

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

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::POSIX

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

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

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::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

This class inherits a constructor from Puppet::Parameter

Class Method Details

.defaultvaluesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/puppet/property/ensure.rb', line 13

def self.defaultvalues
  newvalue(:present) do
    if @resource.provider and @resource.provider.respond_to?(:create)
      @resource.provider.create
    else
      @resource.create
    end
    nil # return nil so the event is autogenerated
  end

  newvalue(:absent) do
    if @resource.provider and @resource.provider.respond_to?(:destroy)
      @resource.provider.destroy
    else
      @resource.destroy
    end
    nil # return nil so the event is autogenerated
  end

  defaultto do
    if @resource.managed?
      :present
    else
      nil
    end
  end

  # This doc will probably get overridden
  @doc ||= "The basic property that the resource should be in."
end

.inherited(sub) ⇒ Object



44
45
46
47
48
# File 'lib/puppet/property/ensure.rb', line 44

def self.inherited(sub)
  # Add in the two properties that everyone will have.
  sub.class_eval do
  end
end

Instance Method Details

#change_to_s(currentvalue, newvalue) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppet/property/ensure.rb', line 50

def change_to_s(currentvalue, newvalue)
  begin
    if currentvalue == :absent || currentvalue.nil?
      return _("created")
    elsif newvalue == :absent
      return _("removed")
    else
      return _('%{name} changed %{is} to %{should}') % { name: name, is: is_to_s(currentvalue), should: should_to_s(newvalue) }
    end
  rescue Puppet::Error, Puppet::DevError
    raise
  rescue => detail
    raise Puppet::DevError, "Could not convert change #{self.name} to string: #{detail}", detail.backtrace
  end
end

#retrieveSymbol

Retrieves the is value for the ensure property. The existence of the resource is checked by first consulting the provider (if it responds to ‘:exists`), and secondly the resource. A a value of `:present` or `:absent` is returned depending on if the managed entity exists or not.

Returns:

  • (Symbol)

    a value of ‘:present` or `:absent` depending on if it exists or not

Raises:

  • (Puppet::DevError)

    if neither the provider nor the resource responds to ‘:exists`



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/puppet/property/ensure.rb', line 74

def retrieve
  # XXX This is a problem -- whether the object exists or not often
  # depends on the results of other properties, yet we're the first property
  # to get checked, which means that those other properties do not have
  # @is values set.  This seems to be the source of quite a few bugs,
  # although they're mostly logging bugs, not functional ones.
  if prov = @resource.provider and prov.respond_to?(:exists?)
    result = prov.exists?
  elsif @resource.respond_to?(:exists?)
    result = @resource.exists?
  else
    raise Puppet::DevError, "No ability to determine if #{@resource.class.name} exists"
  end
  if result
    return :present
  else
    return :absent
  end
end