Class: Puppet::Property::Ensure

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

Overview

This property will get automatically added to any type that responds to the methods ‘exists?’, ‘create’, and ‘destroy’.

Constant Summary

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Instance Attribute Summary

Attributes inherited from Puppet::Property

#noop, #shadow, #shouldorig

Attributes inherited from Puppet::Parameter

#parent, #resource

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Puppet::Property

array_matching, array_matching=, #call_provider, #call_valuemethod, #event, #event_name, #initialize, #insync?, #is_to_s, #log, #match_all?, method_added, #munge, #name, newvalue, #property_matches?, #safe_insync?, #set, #setup_shadow, #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, #devfail, doc, #fail, format_value_for_display, #initialize, initvars, isnamevar, isnamevar?, isrequired, #log, #metaparam?, #munge, munge, #name, newvalues, nodefault, #noop, #pathbuilder, #provider, proxymethods, #remove, required?, #tags, #to_s, unmunge, #unmunge, #unsafe_munge, #unsafe_validate, validate, #validate, #value, #value=

Methods included from Util::Docs

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

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

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

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #send_log

Methods included from Util::LogPaths

#path, #source_descriptors

Methods included from Util::Errors

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

Constructor Details

This class inherits a constructor from Puppet::Property

Class Method Details

.defaultvaluesObject



8
9
10
11
12
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
# File 'lib/vendor/puppet/property/ensure.rb', line 8

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



39
40
41
42
43
# File 'lib/vendor/puppet/property/ensure.rb', line 39

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vendor/puppet/property/ensure.rb', line 45

def change_to_s(currentvalue, newvalue)
  begin
    if currentvalue == :absent or currentvalue.nil?
      return "created"
    elsif newvalue == :absent
      return "removed"
    else
      return "#{self.name} changed '#{self.is_to_s(currentvalue)}' to '#{self.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}"
  end
end

#retrieveObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/vendor/puppet/property/ensure.rb', line 61

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